Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 362
foadk Avatar asked Nov 02 '25 02:11

foadk


1 Answers

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

If it succeeds, the key should be valid.

like image 189
Martin Prikryl Avatar answered Nov 04 '25 20:11

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!