android call MD5 algorithm

public static String getStringMD5(String sourceStr)

{ String s = null;

try {

MessageDigest md = MessageDigest.getInstance("MD5");

// The role of these two lines of code is:

// Convert the bytes array to BigInterger type. 1, means +, which is a positive number.

BigInteger bigInt = new BigInteger(1, md.digest(sourceStr.getBytes()));

// Use the format method to obtain a 32-bit hexadecimal string. 032, representing high-order 0 to 32 bits, X represents hexadecimal integer data.

// Why is 32 bits? Because the MD5 algorithm returns a 128-bit integer, we are used to express it in hexadecimal, which is 32 bits.

s = String.format("%032x", bigInt);

}

catch (NoSuchAlgorithmException e) {

e.printStackTrace ();

}

return s;

}



Author: Oak Mr.
link: https: //www.jianshu.com/p/83fc0c13104c
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Published 10 original articles · Like 11 · Visits 20,000+

Guess you like

Origin blog.csdn.net/u013323018/article/details/83098794
Recommended