Message Digest --- MD5 encryption, digest --- md5 Encryption
Password Encryption
Generally, the "Message Digest" technology is used to encrypt the password to avoid saving the password in "plaintext.
Plaintext: Original Text
Message Abstract
Is a common data integrity testing technology.
The message digest is equivalent to the fingerprint of data information (files, strings ).
Import api: commons-codec
<! -- Apache provides common encoding packages: Message Digest, encryption, decryption, Bese64 encoding, HEX Encoding, and so on -->
<Dependency>
<GroupId> commons-codec </groupId>
<ArtifactId> commons-codec </artifactId>
<Version> 1.10 </version>
</Dependency>
The following is the test code:
/*** Calculate the Digest (MD5) of a file * md5sum passwd */@ Test public void testFileDidest () throws Exception {// The file passwd is saved in the project folder String file = "passwd"; // open the file InputStream in = new FileInputStream (file ); // calculate the MD5 Digest of data in the file String md5 = DigestUtils. md5Hex (in); System. out. println (md5 );}
Output: 7119a2ae9f636c6ffb9029fd71fadf8
The following describes how to obtain salt using Spring Annotations:
Add salt to the database configuration file (db. properties) to improve the security. You can add salt verification to registration and logon.
salt=\u4ECA\u5929\u4F60\u5403\u4E86\u5417\uFF1F
Database Connection Pool configured in the Spring-dao.xml File
<! -- Load the configuration file of the database connection pool --> <util: properties id = "dbConfig" location = "classpath: db. properties"/>
In this way, the salt can be obtained.
@Value("#{dbConfig.salt}")private String salt;