1.MD5介绍
2.使用Commons Codec
2.1 pom.xml
<!--Apache 加密/解密组件--> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.15</version> </dependency>
2.2 com.imooc.oa.utils下增加Md5Utils.java
package com.imooc.oa.utils; import org.apache.commons.codec.digest.DigestUtils; public class Md5Utils { /** * 对源数据生成MD5摘要 * @param source 源数据 * @return MD5摘要 */ public static String md5Digest(String source){ return DigestUtils.md5Hex(source); } /** * 对源数据加盐混淆后生成MD5摘要 * @param source 源数据 * @param salt 盐值 * @return MD5摘要 */ public static String md5Digest(String source,Integer salt){ char[] chars = source.toCharArray(); for (int i= 0 ; i< chars.length ; i++){ chars[i] = (char) (chars[i] + salt); } String target = new String(chars); //System.out.println(target); String md5 = DigestUtils.md5Hex(target); return md5; } }
标签:Md5Utils,封装,String,chars,source,return,008,MD5 From: https://www.cnblogs.com/LLL0617/p/16964688.html