加鹽加密演算法
阿新 • • 發佈:2018-12-12
引入依賴
<dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.6</version> </dependency>
編寫工具類
package com.example.miaosha_xdp.util; import org.apache.commons.codec.digest.DigestUtils; import org.junit.Test; /** * MD5加密 */ public class MD5Util { /** * 鹽值 自己定義 */ public static final String SALT = "1d3dh43d4"; /** * 加鹽加密 * @param password * @return */ public static String inputPassFromPass(String password){ String str=""+SALT.charAt(0)+SALT.charAt(2)+password+SALT.charAt(6)+SALT.charAt(4); return md5(str); } public static String formPassToDBPass(String formPass, String salt) { String str = ""+salt.charAt(0)+salt.charAt(2) + formPass +salt.charAt(5) + salt.charAt(4); return md5(str); } /** * 加密 * @param password * @return */ public static String md5(String password) { return DigestUtils.md5Hex(password); } @Test public void demo(){ System.out.println(inputPassFromPass("123456")); } }