1.java中如何判斷是不是MD5字符
在Java中,可以通過正則表達(dá)式來判斷一個(gè)字符串是否是MD5字符。MD5字符通常是32位長度的十六進(jìn)制字符串,因此可以使用如下的正則表達(dá)式進(jìn)行判斷:文章來源:http://www.zghlxwxcb.cn/news/detail-518168.html
String regex = "^[a-fA-F0-9]{32}$";
String input = "your input string";
boolean isMD5 = input.matches(regex);
?2:Java生成MD5數(shù)據(jù)
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Example {
public static void main(String[] args) {
String input = "Hello, world!";
String md5 = getMD5(input);
System.out.println("MD5 hash of \"" + input + "\" is: " + md5);
}
public static String getMD5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
StringBuilder hexString = new StringBuilder();
for (byte b : messageDigest) {
hexString.append(String.format("%02x", b));
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
文章中掘金文章來源地址http://www.zghlxwxcb.cn/news/detail-518168.html
到了這里,關(guān)于Java中MD5的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!