You can put this in a tool class. When we need to encrypt and transmit user passwords or other important information, call the methods in this tool class. The following is a simple source code:
Import Java. security. messagedigest; import Java. security. nosuchalgorithmexception; /*** an encrypted class ** @ author way **/public class encode {/*** static encryption method ** @ Param codetype * Incoming Encryption Method * @ Param content * pass in the encrypted content * @ return returns the encrypted result */public static string getencode (string codetype, string content) {try {messagedigest digest = messagedigest. getinstance (codetype); // get an instance and pass in the Encryption Method Digest. reset (); // clear digest. updat E (content. getbytes (); // write content. You can specify the encoding method content. getbytes ("UTF-8"); stringbuilder builder = new stringbuilder (); For (byte B: Digest. digest () {builder. append (integer. tohexstring (B> 4) & 0xf); builder. append (integer. tohexstring (B & 0xf);} return builder. tostring ();} catch (nosuchalgorithmexception e) {e. printstacktrace ();} return NULL;} public static void main (string [] ARGs) {string STR = encode. gete Ncode ("MD5", "Hello world! "); // Use MD5 to encrypt system. Out. println (STR); // fc3ff98e8c6a0d3087d515c0473f8677string str1 = encode. getencode (" Sha "," Hello world! "); // Use SHA to encrypt system. Out. println (str1); // performance34d020724ed75a196dfc2ad67c77772d169 }}