问题
Is it possible that ssh-keygen & openssl can generate two different public keys from same private key? Command ssh-keygen -y -f ./my.key
gives (contents after ssh-rsa
in the same line) different public key to the one generated (contents between -----BEGIN PUBLIC KEY-----
and -----END PUBLIC KEY-----
) with command openssl rsa -in my.key -pubout
.
回答1:
It's the same key but different representations. OpenSSL uses X.509 SubjectPublicKeyInfo in ASN.1, usually (including here) wrapped in PEM; OpenSSH (except 'rsa1' keys for SSHv1 which is broken and you shouldn't use) uses the XDR-like SSH wire format, in base64.
Dupe or neardupe:
Convert pem key to ssh-rsa format
RSA Public Key format
Convert RSA public key to RSA DER
Converting an OpenSSL generated RSA public key to OpenSSH format (PHP)
How to convert RSA key to ssh-rsa
How to store/retrieve RSA public/private key (buried in the middle)
and less obvious cross-stack https://security.stackexchange.com/questions/42268/how-do-i-get-the-rsa-bit-length-with-the-pubkey-and-openssl
来源:https://stackoverflow.com/questions/46870569/ssh-keygen-and-openssl-gives-two-different-public-keys