- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我们的应用中,我们遇到了 Android keystore 中的数据突然变得无法访问的问题。我们看到的具体异常如下:
java.security.UnrecoverableKeyException: Failed to obtain information about private key
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePublicKeyFromKeystore(AndroidKeyStoreProvider.java:223)
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore(AndroidKeyStoreProvider.java:259)
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePrivateKeyFromKeystore(AndroidKeyStoreProvider.java:269)
at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:94)
at java.security.KeyStoreSpi.engineGetEntry(KeyStoreSpi.java:474)
at java.security.KeyStore.getEntry(KeyStore.java:1560)
at <PACKAGE_NAME>.EncryptionInteractor.generateKeys(EncryptionInteractor.java:104)
at <PACKAGE_NAME>.EncryptionInteractor.generateKeys(EncryptionInteractor.java:100)
at <PACKAGE_NAME>.EncryptionInteractor.init(EncryptionInteractor.java:93)
at <PACKAGE_NAME>.EncryptionInteractor.<init>(EncryptionInteractor.java:80)
at <PACKAGE_NAME>.EncryptionInteractor.init(EncryptionInteractor.java:65)
at <PACKAGE_NAME>.<APPLICATION_CLASS>.onCreate(APPLICATION_CLASS.java:17)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.security.KeyStoreException: Invalid key blob
at android.security.KeyStore.getKeyStoreException(KeyStore.java:695)
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePublicKeyFromKeystore(AndroidKeyStoreProvider.java:224)
... 21 more
我们无法找到重现该问题的可靠方法。有几篇文章提到了可能导致 keystore “忘记” key 或被锁定的可能状态,例如 here 。然而,据我所知,我们还没有陷入任何这些边缘情况。第一次设置 key 后让设备静置一段时间后似乎会发生这种情况。我们已经在多个模拟器和设备(从 21 到 26 个)上看到了这种情况。此外,这些设备使用滑动解锁或 PIN 码。更改 PIN 码或安全方法似乎不会导致该问题。同样,此问题似乎是在设备闲置几天后发生的。
我发现了另外两个 SO here和 here以及一个 Google issue 。如果我理解正确,两者中链接的答案似乎依赖于调用者在创建 key 时调用 setUserAuthenticationValidityDurationSeconds 的前提,而我们还没有这样做。此外,给定的解决方案似乎仅依赖于删除 key 并生成一个新 key 。
下面是我们针对 >= API 23 版本的 key 设置。我省略了 23 之前版本的 key 生成,因为我们主要在 >= 23 的 API 上看到了这一点。
private static final int RSA_KEY_SIZE = 2048;
private static final String CERT_SUBJECT_STRING = "CN=<COMPANY_NAME> Android App O=<COMPANY_NAME>";
private static final String ANDROID_KEY_STORE = "AndroidKeyStore";
try {
String alias = KEY_NAME;
KeyPairGenerator generator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, ANDROID_KEY_STORE);
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
end.add(Calendar.YEAR, 1);
KeyGenParameterSpec spec = new KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setAlgorithmParameterSpec(new RSAKeyGenParameterSpec(RSA_KEY_SIZE, RSAKeyGenParameterSpec.F4))
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
.setBlockModes(KeyProperties.BLOCK_MODE_ECB)
.setCertificateNotAfter(end.getTime())
.setCertificateNotBefore(start.getTime())
.setCertificateSerialNumber(BigInteger.ONE)
.setCertificateSubject(new X500Principal(CERT_SUBJECT_STRING))
.build();
generator.initialize(spec);
generator.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
e.printStackTrace();
}
然后,我们稍后尝试通过 keyStore.getEntry(KEY_NAME, null)
访问 key 。同样,这会工作一段时间,但随后将开始抛出上述异常。
最佳答案
我还遇到了 KeyStore 的稳定性问题。
解决方案是使用 private key
PrivateKey privKey = ks.getKey(alias, password)
这就是公钥
PublicKey pubKey = ks.getCertificate(alias).getPublicKey();
而不是 getEntry
ks.getEntry(alias, password)
问题不在于您创建 key 的方式,而在于您读取 key 的方式。
一年多以来再也没有遇到过这个问题。
关于android - UnrecoverableKeyException 获取私钥信息失败,KeyStoreException : Invalid key blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48290355/
如何选择随机哈希键?对于 my Flash+Perl card game我正在尝试从哈希中随机选择一张卡片,其中的键是:“6 黑桃”、“6 俱乐部”等,如下所示: my $card; my $i =
每当我收到对端点的请求时,我都会使用openssl crate 生成随 secret 钥。我将使用新生成的 key 来加密请求数据,并将其作为响应发送回去。 use openssl::rsa::{Rs
我们知道,我们在代码中生成的“随机”数实际上是伪随机数。在Java的情况下,它们默认使用时间戳作为随机种子,并且从该点开始确定性地创建时间戳之后产生的每个随机数。 如果您使用随机数生成密码,并且恶意方
我想用java生成一个128位随 secret 钥。我正在使用以下内容: byte[] byteBucket = new byte[bytelength]; randomizer.nextBytes(
这个问题已经有答案了: Pick random property from a Javascript object (9 个回答) 已关闭 7 个月前。 如果我有以下内容: var liststuff
我做了一些研究,找不到我需要的东西,基本上我想生成一个具有以下格式的随 secret 钥 XXX-XXX-XXXX 最佳答案 这是一个快速的 Javascript 解决方案: let r = Math
在 Firebase 中,可以使用 .childByAutoId() 创建随 secret 钥 let newEntry = FBRef.child("category").childByAutoId
假设我有一个带有大量键的对象: const myObject = { "a": 1, "b": 2, "c": 3, ... } 如果我存储了一个单独的 key 列表,
我需要计算一些字符串的签名,并计划这样做: using (HMACSHA256 hmacSha256 = new HMACSHA256( )) { Byte[] dataToHmac
我的任务是生成随机的 80 字节 key ,我决定遵循以下策略 在我的电脑中sizeof(char)=1 所以我创建了一个英文字母数组 char *p=" "; char a[0..26] and i
我正在设计一个广告系统,该系统根据广告的权重(出价)在广告之间随机轮换。 local ads = local ads = { ["a"] = { views = 0,
我有一个整数列表(员工 ID)它们都是8位长(虽然几乎都是00开头,但实际上都是8位长) 我需要为每个员工生成一个 key : - 5 chars including [A-Z][a-z][0-9]
我使用 KeyPairGenerator 生成 RSA key 对,我注意到它始终生成完全匹配的 key ,而不是应有的随 secret 钥?也许有人知道为什么会这样? 我的代码现在看起来像这样: p
我正在运行一个 FIRESTORE 数据库,我想创建一个具有与 firestore 相同的模式 的随 secret 钥。 在链接中,我找到了创建文档后调用的函数with: 'db.ref.add()'
这个问题已经有答案了: Add a property to a JavaScript object using a variable as the name? (14 个回答) Creating ob
我想生成 1M 随机(出现)唯一字母数字键并将它们存储在数据库中。每个 key 的长度为 8 个字符,并且仅使用子集“abcdefghijk n pqrstuvxyz 和 0-9”。 字母 l、m、o
我想生成像“7HzdUakp”这样的唯一 key 。 我想将其放入数据库(mysql)中,但我想要几乎无限的组合。 我可以使用随机函数生成它,但有时它可以生成相同的 key 两次 已解决 - 我根据“
我有一个我似乎无法弄清楚的基本问题。我正在尝试在 AES-256-CBC 中生成一个可用于加密/解密数据的随 secret 钥。 这是我正在做的: require 'openssl' cipher =
如果您对 Azure 网站使用自动缩放,是否需要设置计算 secret 钥,以便可以在计算机之间共享加密的身份验证 token ? 这里有一个问题,似乎be the same正如我所问的那样。然而,这
我想根据创建日期和时间从 Firebase 中检索数据我还没有找到任何其他方法,而不是通过使用 orderByChild("Create") 创建每个用户的 child 来保存创建日期和时间排序,但是
我是一名优秀的程序员,十分优秀!