baidu_28888097 2015-10-13 06:10 采纳率: 0%
浏览 6716

关于 JAVA中PBKDF2WithHmacSHA256加密。

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)

  • 写回答

2条回答 默认 最新

  • WorldMobile 2015-10-14 01:14
    关注

    参考一下这个试试
    报错: java.security.NoSuchAlgorithmException
    http://blog.csdn.net/chexitianxia/article/details/9718045

    评论

报告相同问题?