我已经得到了带有证书和pub/private密钥的PEM文件。具体而言,它包括标题将PEM传统私钥转换为PKCS8私钥
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
-----BEGIN RSA PUBLIC KEY-----
-----END RSA PUBLIC KEY-----
以该特定顺序。
我的理解是在BEGIN RSA PRIVATE KEY
标头后面没有标题,表示此pem文件包含传统格式(PKCS1)的未加密的私钥。
我需要将此私钥转换为DER编码的PKCS8未加密格式,以便与java服务器代码一起使用,特别是PKCS8EncodedKeySpec。我已经尝试过使用rsa和pkcs8命令的OpenSSL,但没有运气。如果有更简单的事情,没有特别需要使用openssl。
具体做法是:
openssl rsa -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem
openssl rsa -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem -pubin openssl pkcs8 -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem -nocrypt
我也试着指定通知和outform没有成功。
[email protected]:~/TestCerts$ openssl rsa -in IServer_Key.pem -out IServer_Key.pkcs8.pem -pubin
unable to load Public Key
5925:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:650:
Expecting: PUBLIC KEY
[email protected]:~/TestCerts$ openssl rsa -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem
unable to load Private Key
5993:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1316:
5993:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:tasn_dec.c:828:
5993:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:748:Field=n, Type=RSA
5993:error:0D09A00D:asn1 encoding routines:d2i_PrivateKey:ASN1 lib:d2i_pr.c:99:
5993:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:125:
[email protected]:~/TestCerts$ openssl pkcs8 -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem -nocrypt
Error decrypting key
6022:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:650:
Expecting: PRIVATE KEY
任何帮助将非常赞赏在这一点上。
我删除了java标记,因为它完全不受java的限制,并且希望它可以获得更广泛的受众 – cfi
我认为大多数OpenSSL命令都希望每个文件都有一个对象(某些手部放弃)。创建第二个文件,只添加私钥(包括'----- BEGIN RSA PRIVATE KEY -----和'----- END RSA PRIVATE KEY -----') 。然后尝试你的命令。 – jww
[OpenSSL pkcs8默认格式提供RSA PRIVATE KEY](https://superuser.com/questions/606215/openssl-pkcs8-default-format-gives-rsa-private-key)。 – jww