我知道它的工作原理,但如果我想将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();
}
HexBinaryAdapter.marshal()
只调用了DatatypeConverter.printHexBinary()
(如果您想避免实例化HexBinaryAdapter
,实际上可以直接使用它),然后DatatypeConverter.printHexBinary()
在第一次调用时实例化一个单例的DatatypeConverterImpl
。之后,就是对DatatypeConverterImpl
的printHexBinary
方法的直接调用。它使用的方法与WhiteFang34的答案非常相似。 - mpontes