小编Chr*_*chi的帖子

Android 指纹 - 加密原语不受 AndroidKeyStore 提供程序支持

我正在尝试将 android 指纹实现到示例应用程序中。使用的密码不被认为是有效的 - 但我不知道为什么,因为基于 android 文档,它应该被支持。

密码建立在:

return Cipher.getInstance(KeyProperties.KEY_ALGORITHM_RSA + "/" +KeyProperties.BLOCK_MODE_ECB + "/" + KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1);
Run Code Online (Sandbox Code Playgroud)

官方文档中列出了此密码。

稍后使用的 keyGenerator 和 keyFactory 生成如下。

            keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null); // Ensure the key store can be loaded before continuing.

            keyGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
            keyFactory = KeyFactory.getInstance("RSA");

            createCipher(); // If this doesn't throw, the cipher we need is available.
Run Code Online (Sandbox Code Playgroud)

我还使用该密码初始化密钥生成器:

 keyGenerator.initialize(new KeyGenParameterSpec.Builder(keyAlias,
                    KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) //
                    .setBlockModes(KeyProperties.BLOCK_MODE_ECB) //
                    .setUserAuthenticationRequired(true) //
                    .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1) //
                    .build());

            keyGenerator.generateKeyPair();
Run Code Online (Sandbox Code Playgroud)

我还将公钥添加到加密过程中,而公钥是这样生成的:

private PublicKey getPublicKey() throws GeneralSecurityException { …
Run Code Online (Sandbox Code Playgroud)

android android-keystore android-security android-fingerprint-api

5
推荐指数
2
解决办法
1670
查看次数

使用Java HashMap多个Type

我正在使用Hashmap作为我的内存缓存.基本上,这就是我所拥有的:

private static final Map<String, Object> lookup = new HashMap<String, Object>();

    public static Object get(CacheHelper key) {
        return lookup.get(key.getId());
    }

    public static void store(CacheHelper key, Object value) {
        lookup.put(key.getId(), value);
    }
Run Code Online (Sandbox Code Playgroud)

没关系.但对于我从地图中"获取"的每个物体,我必须施放,这非常难看.我想把ArrayList和许多其他不同的东西放进去.

有人知道其他解决方案是类型安全的吗?

(当然,我可以为每种类型创建一个getter和setter,但这是唯一的解决方案吗?

那么,是否有更好的方法来创建内存缓存,或者有人知道如何将hashmap包装起来更安全吗?

java arraylist hashmap typesafe

2
推荐指数
1
解决办法
1456
查看次数