如何修复:java.lang.RuntimeException:错误:0c0000af:ASN.1编码例程:OPENSSL_internal:TOO_LONG在生成sharedKey中

时间:2019-01-16 07:57:20

标签: java android encryption public-key-encryption private-key

我尝试使用其他公共密钥和私有密钥创建sharedKey,但是我遇到了异常。

byte[] otherPublicKey = mOtherPublic.getBytes();

        X509EncodedKeySpec pkSpec = new X509EncodedKeySpec(otherPublicKey);
        KeyFactory keyFactory = KeyFactory.getInstance("EC");

        PublicKey otherPublicKey = keyFactory.generatePublic(pkSpec);//in this line i faced to exception

        // Perform key agreement
        KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH");
        keyAgreement.init(mkeyPair.getPrivate());
        keyAgreement.doPhase(otherPublicKey, true);

        // Read shared secret
        byte[] sharedSecret = keyAgreement.generateSecret();

0 个答案:

没有答案