如何将文件存储时使用的MD5加密方法改写成长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计204个文字,预计阅读时间需要1分钟。
javapackage com.cx.bank.util;
import java.security.MessageDigest;
public class MD5Util { public static String encode(byte[] source) { String s=null; char[] hexDigest={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; try { MessageDigest md=MessageDigest.getInstance(MD5); md.update(source); byte[] bytes=md.digest(); StringBuilder sb=new StringBuilder(); for (byte b : bytes) { sb.append(hexDigest[(b & 0xf0) >>> 4]); sb.append(hexDigest[b & 0x0f]); } s=sb.toString(); } catch (Exception e) { e.printStackTrace(); } return s; }}
gistfile1.txtpackage com.cx.bank.util; import java.security.MessageDigest; public class MD5Util { public static String encode(byte[] source){ String s=null; char hexDigest[]={'0','1','2','3','4','5','6','7' ,'8','9','a','b','c','d','e','f'}; try{ MessageDigest md= MessageDigest.getInstance("MD5"); md.update(source); byte tmp[] =md.digest(); char str[]=new char[32]; int k=0; for(int i=0;i<16;i++){ byte byte0=tmp[i]; str[k++]=hexDigest[byte0>>>4&0xf]; str[k++]=hexDigest[byte0&0xf]; } s=new String(str); }catch(Exception e){ e.printStackTrace(); } return s; } public static String getMD5(String source){ return (source==null ||"".equals(source)) ?"":encode(source.getBytes()); } }
本文共计204个文字,预计阅读时间需要1分钟。
javapackage com.cx.bank.util;
import java.security.MessageDigest;
public class MD5Util { public static String encode(byte[] source) { String s=null; char[] hexDigest={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; try { MessageDigest md=MessageDigest.getInstance(MD5); md.update(source); byte[] bytes=md.digest(); StringBuilder sb=new StringBuilder(); for (byte b : bytes) { sb.append(hexDigest[(b & 0xf0) >>> 4]); sb.append(hexDigest[b & 0x0f]); } s=sb.toString(); } catch (Exception e) { e.printStackTrace(); } return s; }}
gistfile1.txtpackage com.cx.bank.util; import java.security.MessageDigest; public class MD5Util { public static String encode(byte[] source){ String s=null; char hexDigest[]={'0','1','2','3','4','5','6','7' ,'8','9','a','b','c','d','e','f'}; try{ MessageDigest md= MessageDigest.getInstance("MD5"); md.update(source); byte tmp[] =md.digest(); char str[]=new char[32]; int k=0; for(int i=0;i<16;i++){ byte byte0=tmp[i]; str[k++]=hexDigest[byte0>>>4&0xf]; str[k++]=hexDigest[byte0&0xf]; } s=new String(str); }catch(Exception e){ e.printStackTrace(); } return s; } public static String getMD5(String source){ return (source==null ||"".equals(source)) ?"":encode(source.getBytes()); } }

