如何转换 PEM 格式的 RSA 公钥:
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
转换为 openssl 格式:
ssh-rsa AAAAB3NzaC1yc2EAA...
尝试过openssl rsa -inform PEM -in id_rsa -pubout
,但得到的是相同的 PEM 格式。阅读手册,但不清楚 openssl 是否可以使用哪些选项进行转换。
$ openssl rsa -help
Usage: rsa [options]
General options:
-help Display this summary
-check Verify key consistency
-* Any supported cipher
-engine val Use engine, possibly a hardware device
Input options:
-in val Input file
-inform format Input format (DER/PEM/P12/ENGINE
-pubin Expect a public key in input file
-RSAPublicKey_in Input is an RSAPublicKey
-passin val Input file pass phrase source
Output options:
-out outfile Output file
-outform format Output format, one of DER PEM PVK
-pubout Output a public key
-RSAPublicKey_out Output is an RSAPublicKey
-passout val Output file pass phrase source
-noout Don't print key out
-text Print the key in text
-modulus Print the RSA key modulus
-traditional Use traditional format for private keys
PVK options:
-pvk-strong Enable 'Strong' PVK encoding level (default)
-pvk-weak Enable 'Weak' PVK encoding level
-pvk-none Don't enforce PVK encoding
Provider options:
-provider-path val Provider load path (must be before 'provider' argument if required)
-provider val Provider to load (can be specified multiple times)
-propquery val Property query used when fetching algorithms
答案1
从表面上看,你想要的是开放的SSH密钥,而不是 OpenSSL 密钥,因此您必须使用 SSH 工具。
尝试ssh-keygen -ef id_rsa >out.tmp
它会在虚线之间给出另一个 base64 代码,但这应该是你需要的。然后你可以用
ssh-keygen -if out.tmp