本文介绍了在“AndroidKeyStore"中使用私钥进行编码()返回空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于 Android 4.3,此代码返回 null.
With Android 4.3, this code return null.
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
keyStore.setKeyEntry(alias, privateKey, null, certificateChain);
PrivateKeyEntry entry=(PrivateKeyEntry)keyStore.getEntry(alias, new PasswordProtection(password));
assert(entry.getPrivateKey().getEncoded()!=null);
如何获得私钥的编码版本?
How it's possible to get the encoded version of private key ?
或者,是否可以将私钥处理程序传输到另一个应用程序?
Or, is it possible to transmit the private key handler to another application ?
谢谢
推荐答案
Android KeyChain API 会阻止您获取编码的私钥.
The Android KeyChain API prevents you from being able to get an encoded private key.
@Override
public final BigInteger getPrivateExponent() {
if (key.isEngineBased()) {
throw new UnsupportedOperationException("private exponent cannot be extracted");
}
但使用 KeyChain API 的好处是它提供了系统范围的凭证存储.任何应用程序都应该能够通过其别名检索密钥对和证书.请参阅 KeyStore 文档.
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.
这篇关于在“AndroidKeyStore"中使用私钥进行编码()返回空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!