我了解它的工作原理,但如果我想将 MD5 打印为字符串,我该怎么做?
public static void getMD5(String fileName) throws Exception{
InputStream input = new FileInputStream(fileName);
byte[] buffer = new byte[1024];
MessageDigest hash = MessageDigest.getInstance("MD5");
int read;
do {
read = input.read(buffer);
if (read > 0) {
hash.update(buffer, 0, read);
}
} while (read != -1);
input.close();
}
最佳答案
你可以少写一点:
String hex = (new HexBinaryAdapter()).marshal(md5.digest(YOUR_STRING.getBytes()))
关于java - 从消息摘要中获取 MD5 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5470219/