在md5之前需要引入shiro相关依赖
<!-- shiro-spring -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.0</version>
</dependency>
package com.rlinux.shirothymeleaf.utils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
/**
* @Description md5加密工具
* @Author RLinux
* @Email RLinux_zwh@163.com
* @Since 2019/3/19 17:03
* @Version 1.0
*/
public class MD5Util {
//干扰数据 盐
private static final String SALT = "RLinux_zwh";
//散列算法类型为MD5
private static final String ALGORITH_NAME = "md5";
//hash次数
private static final int HASH_ITERATIONS = 2;
public static String encrypt(String password) {
String newPassword = new SimpleHash(ALGORITH_NAME, password, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
return newPassword;
}
//盐再加上账号
public static String encrypt(String account, String password) {
String newPassword = new SimpleHash(ALGORITH_NAME, password, ByteSource.Util.bytes(account + SALT),
HASH_ITERATIONS).toHex();
return newPassword;
}
public static void main(String[] args) {
System.out.println(MD5Util.encrypt( "123456"));
System.out.println(MD5Util.encrypt("RLinux", "123456"));
}
}


424

被折叠的 条评论
为什么被折叠?



