使用java加密和解密密码使用什么API和算法

我目前正在使用 Java 创建应用程序,我在谷歌上搜索了 Java 密码加密,但结果如此巨大,我感到不知所措.如何使用 Java 加密和解密密码?加密和解密密码的最佳实践是什么?我猜 MD5 不是一种方法,因为它是一种单向哈希.我使用 struts2 作为我的框架,想知道他们是否提供密码加密

I am currently creating application using Java, I googled password encryption with java but the results are so enormous I felt overwhelmed. How would I encrypt and decrypt a password using Java? And what is the best practice for encrypting and decrypting passwords? I am guessing MD5 is not a way to go since it is a one way hash. I am using struts2 as my framework, was wondering if they provide password encryption

推荐答案

更新:

试试 JBCrypt:

Try JBCrypt:

String password = "MyPassword123";
String hashed = BCrypt.hashpw(password, BCrypt.gensalt(12));
System.out.println(hashed);  // $2a$12$QBx3/kI1SAfwBDFOJK1xNOXK8R2yC7vt2yeIYusaqOisYbxTNFiMy

从此处下载 jBCrypt-0.3,查看 README 文件了解更多详情.

Download jBCrypt-0.3 from here, check README file for more details.

相关文章