zoukankan      html  css  js  c++  java
  • java密码加盐加密

    package AddSalt;
    import java.util.UUID;
    
    import org.apache.shiro.crypto.hash.SimpleHash;
    import org.apache.shiro.util.ByteSource;
     
    public class TestPasswordSalt {
        public static void main(String[] args) {
        	String uuid=UUID.randomUUID().toString().replaceAll("-", "");
        	System.out.println("uuid===="+uuid);
            String pwd1 = md5("123456", "admin"+uuid);
            System.out.println(pwd1);
            
            String uuid1=UUID.randomUUID().toString().replaceAll("-", "");
        	System.out.println("uuid1===="+uuid1);
            String pwd2 = md5("123456", "abc"+uuid1);
            System.out.println(pwd2);
            
        }
     
        public static final String md5(String password, String salt){
            //加密方式
            String hashAlgorithmName = "MD5";
            //盐:相同密码使用不同的盐加密后的结果不同
            ByteSource byteSalt = ByteSource.Util.bytes(salt);
            //密码
            Object source = password;
            //加密次数
            int hashIterations = 2;
            SimpleHash result = new SimpleHash(hashAlgorithmName, source, byteSalt, hashIterations);
            return result.toString();
        }
    }
    

      //pom.xml文件

    <dependencies>
    	   <dependency>
    		   <groupId>org.apache.shiro</groupId>
    		   <artifactId>shiro-spring</artifactId>
    		   <version>1.3.2</version>
    	  </dependency>
      </dependencies>
    

      

  • 相关阅读:
    如何进行简单画图
    缓冲技术
    信号量机制
    进程通信
    中断技术
    操作系统原理-图书主题
    供多处理器系统中的高速缓存同步中使用的转发状态
    js几种escape()解码与unescape()编码
    MySQL 元数据
    MySQL 复制表
  • 原文地址:https://www.cnblogs.com/xianz666/p/14590984.html
Copyright © 2011-2022 走看看