Java comes with an encryption class messagedigest class code example
Messagedigest class
Messagedigest class provides the application with the function of information summarization algorithm, such as MD5 or Sha algorithm. Information digest is a secure one-way hash function, which receives data of any size and outputs a hash value of fixed length.
The messagedigest object began to be initialized. This object processes the data by using the update() method. You can call the reset() method to reset the summary at any time. Once all the data to be updated has been updated, you should call one of the digest() methods to complete the hash calculation.
The digest method can only be called once for a given amount of update data. After calling digest, the messagedigest object is reset to its initial state.
explain:
In the website, in order to protect the user name, password and other privacy information of website members, we directly encrypt the user in MD5 or other ways when registering. Even the database administrator cannot view the password and other information of the member. Check the password effect in the database, such as 8e830882f03b2cb84d1a657f346dd41a effect.
Because MD5 algorithm is irreversible, it is widely used by many websites.
Three commonly used encryption methods
Method 1: use bit operator to convert the encrypted data into hexadecimal mode 2: use format mode to convert the encrypted data into hexadecimal (recommended) mode 3: use algorithm to convert the encrypted data into hexadecimal
Output results
We found that the three methods have the same execution effect, and the Sha length is 8 characters (32 bits) longer than MD5
summary
The above is all about the code example of Java's own encryption class messagedigest class. I hope it will be helpful to you. If there are deficiencies, please leave a message to point out.