In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Java code how to achieve MD5 encryption and verification process, in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
MD5 encryption
In our program, no matter what it is, there will be security problems. Today we are talking about the method of MD5 encryption.
MD5 is a hash algorithm, that is, from plaintext A to ciphertext B is easy, but from ciphertext B to plaintext An is almost impossible.
In other words, if I give you the ciphertext, it is almost impossible to get the plaintext through decryption.
This is generally used to store passwords. That is, the ciphertext is stored in the database, and the administrator can only see the ciphertext, but not the plaintext.
Import related dependencies in a pom file
Org.apache.commons commons-lang3 3.3.2 commons-codec commons-codec
Add MD5 utility class
Import org.apache.commons.codec.digest.DigestUtils;public class Md5 {public final static String md5key = "Ms2"; / * * MD5 method * @ param text plaintext * @ param key key * @ return ciphertext * @ throws Exception * / public static String md5 (String text, String key) throws Exception {/ / encrypted string String encodeStr= DigestUtils.md5Hex (text + key); System.out.println ("MD5 encrypted string is: encodeStr=" + encodeStr); return encodeStr } / * MD5 authentication method * @ param text plaintext * @ param key key * @ param md5 ciphertext * @ return true/false * @ throws Exception * / public static boolean verify (String text, String key, String md5) throws Exception {/ / authenticates String md5Text = md5 (text, key); if (md5Text.equalsIgnoreCase (md5)) {System.out.println ("MD5 authentication passed"); return true;} return false;}}
Briefly talk about the md5 method and the verify method.
Md5 method
Method description: the first parameter for encrypting plaintext is the text that needs to be encrypted, and the second parameter for passing parameter is that key is needed. This method will return the encrypted MD5 ciphertext.
Verify method
Method description: the plaintext is converted to ciphertext, and the ciphertext is compared with the ciphertext to determine whether the first parameter is the plaintext. The second parameter is the key. The third parameter is the ciphertext return.
There is also a variable md5key, which is our key.
Encrypt plaintext through this key
Use when we use this method
To get the key, you can call this variable directly
Of course, this key can also be set by yourself.
This is our MD5 encryption method.
This is the answer to the question about how the java code implements MD5 encryption and verification process. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.