3 回答

侃侃無極
TA貢獻2051條經驗 獲得超10個贊
java.security.MessageDigest
是你的朋友。打電話getInstance("MD5")
若要獲得您可以使用的MD5消息摘要,請執行以下操作。

慕容708150
TA貢獻1831條經驗 獲得超4個贊
如果您實際上希望將答案作為字符串(而不是字節數組)返回,則始終可以執行如下操作:
String plaintext = "your text here";
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plaintext.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while(hashtext.length() < 32 ){
hashtext = "0"+hashtext;
}
添加回答
舉報
0/150
提交
取消