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();
    }

}
posted @ 2020-11-17 20:25  白描先生  阅读(142)  评论(0编辑  收藏  举报
}); });