import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
public static void main(String[] args) throws NoSuchAlgorithmException {
String msg = "這是 MD5 加密的字串";
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(msg.getBytes());
BigInteger number = new BigInteger(1, messageDigest);
String hashtext = number.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
System.out.println(hashtext);
}
}
輸出結果:
e78eed99cf3a2fe3f2fcb79ef6cda47e
全站熱搜
留言列表