- import java.security.MessageDigest;
- ...
- ...
- public static String md5It(String str) throws NoSuchAlgorithmException{
- StringBuffer sb = new StringBuffer();
- // 信息摘要器MessageDigest
- MessageDigest digest = MessageDigest.getInstance("md5");
- byte[] bs = digest.digest(str.getBytes());
- for(byte b : bs){
- int i = b & 0xff;
- String hexString = Integer.toHexString(i);
- if(hexString.length()==1){
- sb.append("0");
- }
- sb.append(hexString);
- System.out.println(sb);
- }
- return sb.toString();
- }
- ...
- ...
复制代码
欢迎勘误。:):) |
|