由网友(我的原则就是没有任何原则)分享简介:在我的应用程序我有一个要求生成一个MD5校验和文件。你能告诉我,如果有在此可以实现什么办法?In my app I have a requirement to generate an MD5 checksum for a file. Could you please tell me if there is any w...
在我的应用程序我有一个要求生成一个MD5校验和文件。你能告诉我,如果有在此可以实现什么办法?
In my app I have a requirement to generate an MD5 checksum for a file. Could you please tell me if there is any way in which this can be achieved?
感谢你。
推荐答案
文件内容转换为字符串和放大器;使用下面的方法:
Convert the file content into string & use the below method:
public static String getMD5EncryptedString(String encTarget){
MessageDigest mdEnc = null;
try {
mdEnc = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
System.out.println("Exception while encrypting to md5");
e.printStackTrace();
} // Encryption algorithm
mdEnc.update(encTarget.getBytes(), 0, encTarget.length());
String md5 = new BigInteger(1, mdEnc.digest()).toString(16);
while ( md5.length() < 32 ) {
md5 = "0"+md5;
}
return md5;
}
相关推荐
最新文章