關於部落格
換個方向思考反而能更真切的看出事物的真實與本質
  • 65509

    累積人氣

  • 2

    今日人氣

    0

    訂閱人氣

[Java][MD5] Java的MD5編碼


import java.util.*;
import java.security.*;
 
public class EncryptBean {
 
public static String encrypt(String str) {
return encrypt(str, "MD5");
}
 
public static String encrypt(String str, String encType) {
String result = "";
try {
MessageDigest md = MessageDigest.getInstance(encType);
md.update(str.getBytes());
result = toHexString(md.digest());
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
 
private static String toHexString(byte[] in) {
StringBuilder hexString = new StringBuilder();
for (int i = 0; i < in.length; i++){
String hex = Integer.toHexString(0xFF & in[i]);
if (hex.length() == 1){
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}
相簿設定
標籤設定
相簿狀態