在Android上使用Conscrypt进行ECC密钥包装

时间:2018-08-29 11:57:48

标签: java android cryptography

我在Android上使用Conscrypt(顺便说一句,我将minSdkVersion设置为23)。我已经写了一些代码来包装和解开ECC公钥。 AES密钥用于此包装/展开:

private void testWrapFunctions(Key eccKey) {

    try {
        byte[] randomAesKey = generateSecureRandomBytes(AES_KEY_SIZE/8);
        SecretKeySpec aesKey = generateAESKey(randomAesKey);

        Cipher myCipher = Cipher.getInstance("AES/GCM/NoPadding");

        myCipher.init(Cipher.WRAP_MODE, aesKey);
        byte[] wrappedData = myCipher.wrap(eccKey);

        myCipher.init(Cipher.UNWRAP_MODE, aesKey);
        Key unWrappedKey = myCipher.unwrap(wrappedData, "AES/GCM/NoPadding", Cipher.PUBLIC_KEY);

    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}

运行此代码时,出现以下异常:

java.lang.RuntimeException: error:0f00007b:elliptic curve routines:OPENSSL_internal:UNKNOWN_GROUP

这是回溯:

System.err:     at org.conscrypt.NativeCrypto.EVP_marshal_public_key(Native Method)
System.err:     at org.conscrypt.OpenSSLECPublicKey.getEncoded(OpenSSLECPublicKey.java:91)
System.err:     at org.conscrypt.OpenSSLCipher.engineWrap(OpenSSLCipher.java:404)
System.err:     at javax.crypto.Cipher.wrap(Cipher.java:1677)
System.err:     at com.st.st25dvcryptodemo.MyApplication.testWrapFunctions(MyApplication.java:187)

您知道我做错了什么吗? 谢谢

0 个答案:

没有答案