This article is an example of how Android implements simple MD5 encryption. Share to everyone for your reference, specific as follows:
Online about Android under the MD5 encrypted data a lot, but the test is always the same as the site's MD5 encryption is not the same, then know that the encoding is not the way, so they wrote one.
private static final char hex_digits[] = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', '
A ', ' B ', ' C ', ' D ', ' E ', ' F '};
public static String tohexstring (byte[] b) {
//string to byte
StringBuilder sb = new StringBuilder (B.length * 2); c5/>for (int i = 0; i < b.length i++) {
sb.append (hex_digits[(b[i) & 0xf0) >>> 4]);
Sb.append (Hex_digits[b[i] & 0x0f]);
}
return sb.tostring ();
}
Public String MD5 (string s) {
try {
//Create MD5 Hash
messagedigest digest = java.security.MessageDigest. getinstance ("MD5");
Digest.update (S.getbytes ());
byte messagedigest[] = Digest.digest ();
Return tohexstring (messagedigest);
} catch (NoSuchAlgorithmException e) {
e.printstacktrace ();
}
Return "";
}
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", "Android Basic Components Usage Summary", " Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.