javaregexsshssh-keys

Validate SSH host key format in Java


is there a nice way to validate format/pattern of a SSH Host Key?

I've seen some guys doing it with regex like this one to validate RSA:

^(ssh-[a-z]{3}) ([0-9]{3,4}) ([0-9a-f]{2}:){15}[0-9a-f]{2}$

Or use a parser like this on Python.

Can you guys help with dsa/ecdsa and ed25519 regex?

I didn't founded a nice parser to do it by Pythonic way on Java :(


Solution

  • Try using KnownHosts class from JSch library.