Android MD5 encryption is identical to the J2SE platform because the Android platform supports java.security.MessageDigest this package. is actually exactly the same as the J2SE platform.
Algorithm Signature:
[Java]View Plaincopy
- String GetMD5 (String val) throws NoSuchAlgorithmException
Enter a string (text that needs to be encrypted) to get an encrypted output string (encrypted text)
[Java]View Plaincopy
- Package com.tencent.utils;
- Import Java.security.MessageDigest;
- Import java.security.NoSuchAlgorithmException;
- /**
- * GETMD5 (String) method available externally
- * @author Randyjia
- *
- */
- Public class MD5 {
- public static string GetMD5 (string val) throws nosuchalgorithmexception{
- MessageDigest MD5 = messagedigest.getinstance ("MD5");
- Md5.update (Val.getbytes ());
- byte[] m = md5.digest (); //Encryption
- return getString (m);
- }
- private static String getString (byte[] b) {
- StringBuffer sb = new StringBuffer ();
- For (int i = 0; i < b.length; i + +) {
- Sb.append (B[i]);
- }
- return sb.tostring ();
- }
- }
SHA-1
NULL ; Try { digester = messagedigest.getinstance ("SHA-1"); Catch (nosuchalgorithmexception e) { // TODO auto-generated catch block E.printstacktrace (); } Digester.update (calhashdata); byte [] Hashd = Digester.digest ();
Implementation of hash SHA1 and MD5 under Java/android