版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zwl18210851801/article/details/84975584
pom引入:
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.3.2</version>
</dependency>
工具方法:
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
/**
* MD5加密工具
*
* @author ZhangWanLong
* @date 2017年8月8日 下午5:17:34
*/
public class MD5Utils {
private static final String SALT = "3qwerzxsw2";
private static final String ALGORITH_NAME = "md5";
private static final int HASH_ITERATIONS = 2;
/**
* 使用md5生成加密后的密码
* @param pswd
* @return
*/
public static String encrypt(String pswd) {
String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
return newPassword;
}
/**
* 使用md5生成加密后的密码
* @param username
* @param pswd
* @return
*/
public static String encrypt(String username, String pswd) {
String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username + SALT), HASH_ITERATIONS).toHex();
return newPassword;
}
}