Public classEncryptutil { Public Staticstring Getencrypt (string value, String encrypt_type) {string Md5_str=NULL ; Try { //Get a MD5 Cryptographic Information Digest instance Note that parameters can only be MD5, SHAMessageDigest MD = messagedigest.getinstance ("MD5"); //converts a string into a byte array, and then obtains a message digest byte array from the byte array byte[] Digest =md.digest (Str.getbytes ()); //creating the Sun.misc.BASE64Encoder instance encoding toolSun.misc.BASE64Encoder encoder =NewSun.misc.BASE64Encoder (); //encode a byte array of information digest using the Encode method of the Encoding tool returns a string that is the result string of the encryptionString Md5_str =Encoder.encode (Digest); System.out.println (MD5_STR); } Catch(nosuchalgorithmexception e) {e.printstacktrace ();}returnmd5_str;}
Md5/sha encryption