StupidBeauty
Read times:816Posted at:Sun Sep 8 19:39:49 2013
- no title specified

转载:Android使用MD5加密算法加密密码

这里有一段代码,用来在Java中计算MD5散列,经验证它的计算结果是正确的,可以直接拿来用。

http://www.android-study.com/pingtaikaifa/186.html

亮点:

// MD5加密,32位

public static String MD5(String str) {

MessageDigest md5 = null;

try {

md5 = MessageDigest.getInstance("MD5");

} catch (Exception e) {

e.printStackTrace();

return "";

}

char[] charArray = str.toCharArray();

byte[] byteArray = new byte[charArray.length];

for (int i = 0; i < charArray.length; i++) {

byteArray[i] = (byte) charArray[i];

}

byte[] md5Bytes = md5.digest(byteArray);

StringBuffer hexValue = new StringBuffer();

for (int i = 0; i < md5Bytes.length; i++) {

int val = ((int) md5Bytes[i]) & 0xff;

if (val < 16) {

hexValue.append("0");

}

hexValue.append(Integer.toHexString(val));

}

return hexValue.toString();

}

未知美人

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4