可以使用X509EncodedKeySpec在java中加载公钥,但无法使用openssl对其进行解析
我有一对私钥/公钥,由其他人生成并传递给我。该对当前正在活动部署中使用。这两个密钥都存储在扩展名为.der的文件中。 我可以正确验证和解析的私钥: openssl pkcs8-INFORT DER-nocrypt-in private_key.DER 但是,Public one在以下方面失败: 解密密钥139834801850032时出错:错误:0D0680A8:asn1编码 例行程序:ASN1\u检查:错误标签:tasn\u dec.c:1338: 139834801850032:错误:0D06C03A:asn1编码 例程:ASN1_D2I_EX_原语:嵌套ASN1错误:tasn_dec.c:852: 139834801850032:错误:0D08303A:asn1编码 例程:ASN1\U模板\U NOEXP\U D2I:嵌套ASN1 错误:tasn\u dec.c:772:Field=version,Type=PKCS8\u PRIV\u KEY\u INFO 公钥当前由java应用程序使用,并按如下方式加载:可以使用X509EncodedKeySpec在java中加载公钥,但无法使用openssl对其进行解析,java,openssl,public-key,Java,Openssl,Public Key,我有一对私钥/公钥,由其他人生成并传递给我。该对当前正在活动部署中使用。这两个密钥都存储在扩展名为.der的文件中。 我可以正确验证和解析的私钥: openssl pkcs8-INFORT DER-nocrypt-in private_key.DER 但是,Public one在以下方面失败: 解密密钥139834801850032时出错:错误:0D0680A8:asn1编码 例行程序:ASN1\u检查:错误标签:tasn\u dec.c:1338: 139834801850032:错误:0D0
byte[] publicKeyArray - <the public key bytes straight from file>
X509EncodedKeySpec spec = new X509EncodedKeySpec(publicKeyArray);
KeyFactory factory = KeyFactory.getInstance("RSA");
java.security.PublicKey publicKey = factory.generatePublic(spec);
我尝试过使用不同的openssl命令,包括asn1parse,但没有成功。如何使用java X509EncodedKeySpec以外的其他工具从文件中使用/提取公钥?我自己也在想这个问题。如果你已经有了一个解决方案,如果你能分享它,那就太好了。如果没有,我很乐意尝试帮助想出一个解决方案。
* This class represents the ASN.1 encoding of a public key,
* encoded according to the ASN.1 type {@code SubjectPublicKeyInfo}.
* The {@code SubjectPublicKeyInfo} syntax is defined in the X.509
* standard as follows:
*
* <pre>
* SubjectPublicKeyInfo ::= SEQUENCE {
* algorithm AlgorithmIdentifier,
* subjectPublicKey BIT STRING }
* </pre>
* Creates a new X509EncodedKeySpec with the given encoded key.
*
* @param encodedKey the key, which is assumed to be
* encoded according to the X.509 standard. The contents of the
* array are copied to protect against subsequent modification.
* @exception NullPointerException if {@code encodedKey}
* is null.
*/