一、不带盐值加密
1、将前台传过来的密码进行MD5加密。将当前的Realm 的credentialsMatcher属性,替换为Md5CredentialsMatcher 由于Md5CredentialsMatcher已经过期了,推荐使用HashedCredentialsMatcher 并设置加密算法即可。
2、配置HashedCredentialsMatcher,通过
setHashAlgorithmName:设置加密算法的名称
etHashIterations:设置加密的次数
3、HashedCredentialsMatcher通过
new SimpleHash("MD5","123456",null,1024);进行加密。参数依次为:加密算法,后台接收到的密码,盐,加密的次数。
通过也可以通过该方法进行测试,输出加密后的密码
Object object = new SimpleHash("MD5","123456",null,1024); System.out.println(object);
把加密后的内容打印
package com.springbootshiro.springbootshiro.config;
import com.springbootshiro.springbootshiro.realm.UserRealm;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.s