自编算法存在安全风险,维护起来很痛苦.
MD5 不安全.
使用jBcrypt提供的bcrypt算法(开源):
// Hash a password
String hashed = BCrypt.hashpw(password, BCrypt.gensalt());
// Check that an unencrypted password matches or not
if (BCrypt.checkpw(candidate, hashed))
System.out.println("It matches");
else
System.out.println("It does not match");
Run Code Online (Sandbox Code Playgroud)
如果您使用Maven,可以通过在pom.xml中插入以下依赖项来获取库(如果有更新的版本可以请告诉我):
<dependency>
<groupId>de.svenkubiak</groupId>
<artifactId>jBCrypt</artifactId>
<version>0.4.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)