The encryption algorithm

Abstract Algorithm: MD5 128-bit digest fast speed no matter how big the data, the process is irreversible SHA1 160-bit digest strength is displayed in a fixed length

Main uses: verify information integrity, secure access authentication, data signature decryption by dictionary method.

Symmetric encryption algorithm: AES 128-bit, 192-bit, 256-bit Faster encryption and higher security DES 56-bit, 112-bit, 168-bit Feature: Use the same key for encryption and decryption.

Asymmetric encryption FEATURES of RSA: Asymmetric encryption and decryption use different secret keys, including public keys and secret keys.

The example uses digest algorithm to encrypt

Inject dependencies:

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
<scope>provided</scope>
</dependency>
Copy the code

Example code:


public static String sha256Hex(String value) {
return DigestUtils.sha256Hex(value);
}

public static String sha512Hex(String value) {
return DigestUtils.sha512Hex(value);
}

// Combine according to business needs (dictionary)
public static String md5Hex3(String value) {
for (int i = 0; i < 3; i++) {
value = DigestUtils.md5Hex(value);
}
returnvalue; }}Copy the code

Here’s an example:

  • During password authentication, the dictionary is used to encrypt the input string and compare it with the same encrypted password stored in the database to ensure that the password will not be leaked in the background database.