Java 两次MD5

导入:

import org.apache.commons.codec.digest.DigestUtils;

  代码:

1public static String md5(String src) { 2 return DigestUtils.md5Hex(src); 3 } 4 5 private static final String salt = "1a2b3c4d"; 6 7 public static String inputPassToFormPass(String inputPass) { 8 String str = ""+salt.charAt(0)+salt.charAt(2) + inputPass +salt.charAt(5) + salt.charAt(4); 9 System.out.println(str); 10 return md5(str); 11 } 12 13 public static String formPassToDBPass(String formPass, String salt) { 14 String str = ""+salt.charAt(0)+salt.charAt(2) + formPass +salt.charAt(5) + salt.charAt(4); 15 return md5(str); 16 } 17 18 public static String inputPassToDbPass(String inputPass, String saltDB) { 19 String formPass = inputPassToFormPass(inputPass); 20 String dbPass = formPassToDBPass(formPass, saltDB); 21 return dbPass; 22 }

  md5:帮助类

1import java.io.File; 2import java.io.FileInputStream; 3import java.nio.MappedByteBuffer; 4import java.nio.channels.FileChannel; 5import java.security.MessageDigest; 6 7/** 8 * MD5加密工具类 9 */ 10public class MD5Util { 11 private static final char DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', 12 '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 13 14 /** 15 * 获取文件的MD5码 16 * 17 * @param absPath 18 * 文件路径 19 * @return 文件的MD5码 20 */ 21 public final static String getFileMD5(String absPath) { 22 try { 23 File file = new File(absPath); 24 MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 25 FileInputStream fis = new FileInputStream(file); 26 FileChannel filechannel = fis.getChannel(); 27 MappedByteBuffer mbb = filechannel 28 .map(FileChannel.MapMode.READ_ONLY, 0, file.length()); 29 mdTemp.update(mbb); 30 byte[] md = mdTemp.digest(); 31 int j = md.length; 32 char str[] = new char[j * 2]; 33 int k = 0; 34 for (int i = 0; i < j; i++) { 35 byte byte0 = md[i]; 36 str[k++] = DIGITS[byte0 >>> 4 & 0xf]; 37 str[k++] = DIGITS[byte0 & 0xf]; 38 } 39 fis.close(); 40 return new String(str); 41 } catch (Exception e) { 42 return ""; 43 } 44 } 45 46 /** 47 * 获取指定字符串的MD5码 48 * 49 * @param s 50 * 字符串 51 * @return 字符串的MD5码 52 */ 53 public final static String getMD5(String s) { 54 char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 55 'a', 'b', 'c', 'd', 'e', 'f' }; 56 try { 57 byte[] strTemp = s.getBytes(); 58 MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 59 mdTemp.update(strTemp); 60 byte[] md = mdTemp.digest(); 61 int j = md.length; 62 char str[] = new char[j * 2]; 63 int k = 0; 64 for (int i = 0; i < j; i++) { 65 byte byte0 = md[i]; 66 str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 67 str[k++] = hexDigits[byte0 & 0xf]; 68 } 69 return new String(str); 70 } catch (Exception e) { 71 return null; 72 } 73 } 74 75 public static void main(String[] args) { 76 System.out.println(getMD5("admin")); 77 } 78}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Java日期时间API系列31

  时间戳是指格林威治时间1970年01月01日00时00分00秒起至现在的总毫秒数,是所有时间的基础,其他时间可以通过时间戳转换得到。Java中本来已经有相关获取时间戳的方法,Java8后增加新的类Instant等专用于处理时间戳问题。 1获取时间戳的方法和性能对比1.1获取时间戳方法Java8以前

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Java日期时间API系列35

  通过Java日期时间API系列1Jdk7及以前的日期时间类(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.cnblogs.com%2Fxkzhangsanx%2Fp%2F12032719.html)中得知,Java8以前除了java.sql.Timestamp扩充