foadk
foadk

Reputation: 43

Is there a way to validate SSH public key in PHP?

I want to validate a user submitted public key in php. I want something equivalent to ssh-keygen -lf command.

I've tried violuke/rsa-ssh-key-fingerprint, but unlike ssh-keygen -lf, it does not say if public key is valid or not. It returns a hash regardless of key being valid or not. How can I validate public key in PHP?

Upvotes: 4

Views: 1773

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202272

Try load your key using PublicKeyLoader::load from phpseclib.

If it succeeds, the key should be valid.

Upvotes: 3

Related Questions