encode() with private key in “AndroidKeyStore” return null

前端 未结 1 844
一个人的身影
一个人的身影 2021-01-14 01:43

With Android 4.3, this code return null.

KeyStore keyStore = KeyStore.getInstance(\"AndroidKeyStore\");
keyStore.load(null);
keyStore.setKeyEntry(alias, priv         


        
相关标签:
1条回答
  • 2021-01-14 02:28

    The Android KeyChain API prevents you from being able to get an encoded private key.

    See the method at line 158 of OpenSSLRSAPrivateKey.java

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

    But the benefit of using the KeyChain API is that it provides system-wide credential storage. Any app should be able to retrieve the key pair and certificate by its alias. Refer to the KeyStore docs.

    0 讨论(0)
提交回复
热议问题