This article is reproduced from: Portal, theft code shameful, we are the code of the porter, only handling, not stolen code
Package cc.restyle.util;
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException; /** * SHA-512 Encryption * */public class SHA512 {/** incoming text content, return SHA-256 String */public static string encry256 (final Strin
G StrText) {return SHA (StrText, "SHA-256"); /** incoming text content, return SHA-512 String */public static string encry512 (final String strText) {return Sha (StrText, "Sha
-512 ");
}/** String sha encryption */private static string Sha (Final String strtext,final string strtype) {//return value
String Strresult=null;
Whether it is a valid string if (StrText! = null && strtext.length () >0) {///encrypt start, create encrypted object, and pass in the encryption type
try {messagedigest messagedigest = messagedigest.getinstance (strtype);
Incoming encrypted string messagedigest.update (Strtext.getbytes ());
Get bytes type result byte[] Bytebuffer = Messagedigest.digest (); Convert byte to String
StringBuffer strhexstring = new StringBuffer ();
for (int i =0;i<bytebuffer.length;i++) {String hex = integer.tohexstring (0xFF & Bytebuffer[i]);
if (Hex.length () ==1) {strhexstring.append (' 0 ');
} strhexstring.append (hex);
}//Get the result returned strresult = Strhexstring.tostring ();
} catch (NoSuchAlgorithmException e) {e.printstacktrace ();
}} return strresult;
}
}