【发布时间】:2015-10-19 08:32:42
【问题描述】:
我将 PBEWITHSHA256AND256BITAES-CBC-BC 与 BouncyCastle 一起使用。
public static String algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC";
我已经用这个方法生成秘钥了:
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 需要相同吗?生成密钥的迭代次数和生成 Cipher 对象的迭代次数有多少“重要”(就安全性而言)?它们可以不同吗?
【问题讨论】:
标签: java android security aes pbkdf2