1、导入包

import org.apache.shiro.crypto.hash.SimpleHash;
  • 1

2、代码

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
/*  
 * @Description 散列算法 生成数据的摘要信息,是一种不可逆的算法,一般适合存储密码之类的数据,
 * @Author Madr  
 * @Date 2018/3/24 13:28  
 */
public class MD5Utils {
    //干扰数据 盐 防破解
    private static final String SALT = "mar%#$@";
    //散列算法类型为MD5
    private static final String ALGORITH_NAME = "md5";
    //hash的次数
    private static final int HASH_ITERATIONS = 2;

    public static String encrypt(String pswd) {
        String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT),HASH_ITERATIONS).toHex();
        return newPassword;
    }
    public static void main(String[] args) {
        System.out.println("加密后String"+MD5Utils.encrypt("123"));
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-11-28
  • 2022-01-18
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2021-11-21
  • 2021-06-12
相关资源
相似解决方案