Android KeyStore private exponent cannot be extracted

后端 未结 1 521
一个人的身影
一个人的身影 2021-02-05 22:32

I want to generate a RSA keypair in the Android Keystore. Since Android 4.3 is should be possible to generate RSA keys in the Android system Keystore.

I generate my RSA

相关标签:
1条回答
  • 2021-02-05 23:02

    According to the code, I think that the OpenSSL provider prevents the private exponent to be exported when the key has been generated into the device.

    @Override
    public final BigInteger getPrivateExponent() {
        if (key.isEngineBased()) {
            throw new UnsupportedOperationException("private exponent cannot be extracted");
        }
    
        ensureReadParams();
        return privateExponent;
    }
    

    Thus, you probably need to specify that you want to use the same crypto provider when retrieving the cipher instance. This provider supports these RSA ciphers:

    • RSA/ECB/NoPadding
    • RSA/ECB/PKCS1Padding

    You should create an instance of the cipher this way:

    Cipher cipher1 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
    
    0 讨论(0)
提交回复
热议问题