public class SHA256 {
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();
}
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException {
byte [] slat={'9','T','u','x','w','O','z','X','c','m','e','y'};
byte[]pwd=getEncryptedPassword("123456",slat, 12000, 256);
}
}
上面是源码,不知道为什么 我一运行 就报错。
Exception in thread "main" java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA256 SecretKeyFactory not available
at javax.crypto.SecretKeyFactory.(DashoA13*..)
at javax.crypto.SecretKeyFactory.getInstance(DashoA13*..)
at TestLZQ.SHA256.getEncryptedPassword(SHA256.java:26)
at TestLZQ.SHA256.main(SHA256.java:34)