我最近在开发一个关于 Android 的“安全密钥导入”功能的解决方案(详细信息),但遇到了问题。
我按照文档中的步骤进行操作。在最后一步中,调用
一些相关的代码:
我按照文档中的步骤进行操作。在最后一步中,调用
keyStore.setEntry(...)
时,我收到一个错误代码为-1000
的错误,该错误代码是KM_ERROR_UNKNOWN_ERROR
(错误代码)。我真的不知道从这里怎么继续了。有什么想法吗?一些相关的代码:
// (app) send attestation challenge request to server
// (server) generate and send challenge to the app
// (app) use challenge to generate a PURPOSE_WRAP_KEY key pair
// (app) get certificate and send to server
// (server) do wrap operations and return a blob (ASN.1 sequence as required in docs)
// (app) code below
byte[] wrappedKeySequence = response.body().getSequenceAsBytes();
AlgorithmParameterSpec spec = new KeyGenParameterSpec.Builder(WRAP_KEY_ALIAS, KeyProperties.PURPOSE_WRAP_KEY)
.setDigests(KeyProperties.DIGEST_SHA256)
.build();
KeyStore.Entry wrappedKeyEntry = new WrappedKeyEntry(wrappedKeySequence, WRAP_KEY_ALIAS, WRAP_ALGORITHM, spec);
String keyAlias = "SECRET_KEY";
keyStore.setEntry(keyAlias, wrappedKeyEntry, null);
更多随机细节:
- 我正在尝试导入一个AES128密钥
- 它仅用于加密数据
- 以符合文档要求,目标 API 版本为 28 及以上
再次感谢,任何帮助都将不胜感激。
谢谢, G.