其他分享
首页 > 其他分享> > MD5Utils

MD5Utils

作者:互联网



import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class MD5Utils {

    protected MD5Utils() {

    }

    /**
     * 盐值 可随机生成 UUID.randomUUID().toString();
     */
    private static final String SALT = "cws";
    /**加密方式*/
    private static final String ALGORITH_NAME = "md5";
    /**加密的哈希值次数*/
    private static final int HASH_ITERATIONS = 2;

    public static String encrypt(String pswd) {
        return new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
    }

    /**全方面的加密*/
    public static String encrypt(String username, String pswd) {
        return new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username.toLowerCase() + SALT), HASH_ITERATIONS).toHex();
    }

}

标签:MD5Utils,HASH,String,ByteSource,static,ITERATIONS,pswd
来源: https://www.cnblogs.com/cwshuo/p/13996274.html