我有一个私人/公钥对,由其他人生成并传给我 . 该对目前用于主动部署 . 两个密钥都存储在扩展名为.der的文件中 . 私钥我可以验证并解析好吧:

openssl pkcs8 -inform DER -nocrypt -in private_key.der

然而,公共的失败了:

解密密钥错误139834801850032:错误:0D0680A8:asn1编码例程:ASN1_CHECK_TLEN:错误标记:tasn_dec.c:1338:139834801850032:错误:0D06C03A:asn1编码例程:ASN1_D2I_EX_PRIMITIVE:嵌套asn1错误:tasn_dec.c:852:139834801850032:错误:0D08303A:asn1编码例程:ASN1_TEMPLATE_NOEXP_D2I:嵌套asn1错误:tasn_dec.c:772:Field = version,Type = PKCS8_PRIV_KEY_INFO

公钥当前由java应用程序使用,并按如下方式加载:

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);

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.
     */

我试过尝试不同的openssl命令,包括asn1parse但没有运气 . 如何使用java X509EncodedKeySpec以外的其他东西从我的文件中使用/提取公钥?