最近又写了一次SpringBoot整合ApacheShiro注解版,比起spring security,项目体量不大的话还是shiro好
package net.add1s.util;
import org.apache.shiro.crypto.hash.SimpleHash;
/**
* @author pj.w@qq.com
*/
public class Md5Util {
/**
* 加密方式
*/
private static final String ALGORITHM_NAME = "MD5";
/**
* 默认盐值
*/
private static final String DEFAULT_SALT = "add1s.net";
/**
* 默认加密次数
*/
private static final int DEFAULT_ITERATIONS = 1024;
/**
* 返回盐值
*
* @return private static final String SALT 盐值
*/
public static String getDefaultSalt() {
return DEFAULT_SALT;
}
/**
* 返回加密次数
*
* @return private static final int HASHITERATIONS 加密次数
*/
public static int getDefaultIterations() {
return DEFAULT_ITERATIONS;
}
/**
* MD5加密
*
* @param source 待加密源数据
* @return md5's string
*/
public static String md5String(String source) {
return new SimpleHash(ALGORITHM_NAME, source, DEFAULT_SALT, DEFAULT_ITERATIONS).toString();
}
/**
* MD5加密
*
* @param source 待加密源数据
* @param salt 盐值
* @return md5's string
*/
public static String md5String(String source, String salt) {
return new SimpleHash(ALGORITHM_NAME, source, salt, DEFAULT_ITERATIONS).toString();
}
/**
* MD5加密
*
* @param source 待加密源数据
* @param salt 盐值
* @param iterations 加密次数
* @return md5's string
*/
public static String md5String(String source, String salt, int iterations) {
return new SimpleHash(ALGORITHM_NAME, source, salt, iterations).toString();
}
}
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.0</version>
</dependency>