【发布时间】:2018-09-10 09:16:30
【问题描述】:
我使用here的解决方案:
public static byte[] getEncryptedPassword(String password, byte[] salt, int iterations, int derivedKeyLength) throws NoSuchAlgorithmException, InvalidKeySpecException {
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, derivedKeyLength * 8);
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
return f.generateSecret(spec).getEncoded();
}
问题是当我这样做时:
System.out.println(new String(getEncryptedPassword(p,s,i,l)));
我得到一个非常奇怪的字符串,例如���:,但我想要一个可以保存在数据库中的普通字符串。我的错误是什么?
【问题讨论】: