You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB
Java

package com.kiisoo.ic.utils;
import com.kiisoo.ic.system.entity.PrivilageAccountDO;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
/**
*
* @author Arvin
*
*/
public class PasswordEncry {
/** 指定散列算法为md5 */
public static String algorithmName = "MD5";
/** 散列迭代次数 */
public final static int hashIterations = 2;
/** 随机数生成器 */
private static RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
/**
*
* @param userDO
* @return
*/
public PrivilageAccountDO encrypt(PrivilageAccountDO userDO) {
userDO.setSalt(randomNumberGenerator.nextBytes().toHex());
String newPassword = new SimpleHash(algorithmName,userDO.getPassword(), ByteSource.Util.bytes(userDO.getCredentialsSalt()),hashIterations).toHex();
userDO.setPassword(newPassword);
return userDO;
}
}