gpt4 book ai didi

java - Android 上的 PBEWITHSHA256AND256BITAES-CBC-BC : number of iterations for keygeneration and cipher?

转载 作者:行者123 更新时间:2023-11-30 01:59:41 24 4
gpt4 key购买 nike

我将 PBEWITHSHA256AND256BITAES-CBC-BC 与 BouncyCaSTLe 结合使用。

public static String algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC";

我已经完成了这个方法来生成 key :

private void generateSK(char[] passPhrase, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException {
pbeParamSpecKey = new PBEParameterSpec(salt,1000);
PBEKeySpec pbeKeySpec = new PBEKeySpec(passPhrase);
SecretKeyFactory secretKeyFactory;

secretKeyFactory = SecretKeyFactory.getInstance(algorithm);
secretKey = secretKeyFactory.generateSecret(pbeKeySpec);
}

然后生成 Cipher 对象(用于加密或解密):

protected Cipher getCipher(int mode) {
try {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(mode, secretKey, pbeParamSpecKey);

return cipher;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}

pbeParamSpecKey 需要相同吗?生成 key 的迭代次数和生成 Cipher 对象的迭代次数“重要”(就安全性而言)有多少?它们可以不同吗?

最佳答案

The pbeParamSpecKey need to be the same? How much is "important" (in terms of security) the number of iterations generating the key and the one generating the Cipher object?

这是一个您需要自己回答的难题。一般的指导原则是,在不打扰用户的情况下尽可能大,但现在 1000 次迭代有点低。

接下来您需要做的是尝试在您的用户组可能拥有的不同设备上对您的应用程序进行基准测试。然后你可以相应地微调。

也许您可以稍微重新设计您的应用程序,以便在空闲阶段在后台进行 key 派生,因此可能需要更长的时间。但是,这可能会引入其他问题,例如保持派生 key 安全且不可泄漏。

Can they be different?

AES 是一种对称分组密码,因此需要相同 key 进行加密和解密。要生成相同 key ,您需要使用相同 PBKDF2 的密码、salt 和迭代次数。

关于java - Android 上的 PBEWITHSHA256AND256BITAES-CBC-BC : number of iterations for keygeneration and cipher?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31682187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com