Common encryption algorithms such as Java MD5 and SHA256

foreword

When we are doing javaproject development, in the front-end and back-end interface separation mode, interface information needs to be encrypted, signature authentication, and user login information and passwords also need data encryption. 信息加密It is a technology that almost all projects need to use now. Encryption algorithms are often used in scenarios such as identity authentication, single sign-on, information communication, and payment transactions. The so-called encryption algorithm is to transform the original plaintext into a into ciphertext.

  1. BASEStrictly speaking, it belongs to the encoding format, not the encryption algorithm
    MD(Message Digest algorithm, information digest algorithm)
    SHA(Secure Hash Algorithm, secure hash algorithm)
    HMAC(Hash Message Authentication Code, hash message authentication code)

  2. In the encryption algorithm SHA1、SHA-224、SHA-256、SHA-384, and SHA-512, among them SHA-224、SHA-256、SHA-384, and SHA-512we can collectively refer to SHA2the encryption algorithm

  3. SHAThe security of the encryption algorithm is MD5higher than SHA2that of the encryption algorithm SHA1. The SHAfollowing number indicates the length of the encrypted string, and a one-bit information digest SHA1will be generated by default .160

MD5

MD5 Message Digest Algorithm (English: MD5 Message-Digest Algorithm), a widely used cryptographic hash function, can generate a 128-bit (16 byte) hash value (hash value), used to ensure information transmission Completely consistent.

The MD5 algorithm has the following characteristics:

  1. Compressibility: Regardless of the data length, the calculated MD5 value has the same length

  2. Ease of calculation: easy to calculate the MD5 value from the original data

  3. Resistant to modification: Even if one byte is modified, the calculated MD5 value will be greatly different

  4. Anti-collision: Knowing the data and MD5 value, there is a small probability of finding the original data with the same MD5 value

To be precise, MD5 is not an encryption algorithm, but a digest algorithm. MD5 can output plaintext as a 128-bit string, which cannot be converted into plaintext. Some MD5 decryption websites on the Internet only save the md5 strings corresponding to some strings, and find out the original text through the recorded md5 strings.

In the several projects I have done, I often see the scene where MD5 is used for encryption. For example, for password encryption, after generating a password, use MD5 to generate a 128-bit string and save it in the database. After the user enters the password, the MD5 string is also generated first, and then compared in the database. Therefore, we cannot get the original password when we retrieve the password, because the plaintext password will not be saved at all.

SHA series

  1. Secure Hash Algorithm (English: Secure Hash Algorithm, abbreviated as SHA) is a family of cryptographic hash functions and is a secure hash algorithm certified by FIPS. An algorithm that can calculate a fixed-length string (also known as a message digest) corresponding to a digital message. And if the input messages are different, there is a high probability that they correspond to different strings.
  2. At the end of the CRYPTO conference on August 17, 2005, Wang Xiaoyun, Yao Qizhi, and Yao Chufeng once again published a more efficient SHA-1 attack method, which can find collisions within 2 to the power of 63 computational complexity.

That is to say, SHA-1the encryption algorithm has the possibility of collision, although it is very small.

HMAC

  1. HMAC is the abbreviation of key-related hash operation message authentication code (Hash-based Message Authentication Code), which was proposed by H. Krawezyk, M. Bellare, R. Canetti in 1996 based on Hash function and key The authentication method, published as RFC2104 in 1997 and SSLwidely used in IPSec and other network protocols such as , has now become the de facto Internet security standard. It can be bundled with any iterative hash function.
  2. The HMAC algorithm is more like a kind 加密算法, it introduces 密钥, its security is no longer completely dependent on the Hash algorithm used

If you want to use it 加密, it is recommended to use SHA256, SHA384, SHA512 and HMAC-SHA256, HMAC-SHA384, HMAC-SHA512 algorithms.

Symmetric encryption algorithm

  1. The symmetric encryption algorithm is an earlier algorithm, and the same key is used for data encryption and decryption, which causes difficulties in key management. Common symmetric encryption algorithms include DES、3DES、AES128、AES192、AES256(the JDK installed by default does not support AES256 yet, you need to install the corresponding jce patch to upgrade jce1.7, jce1.8). The number behind AES represents the key length. The security of the symmetric encryption algorithm is relatively low, and the more applicable scenario is the encryption and decryption in the intranet environment.

  2. The so-called symmetric encryption means that it can be passed after being encrypted by a key 密钥解密. A certain state-owned enterprise I have contacted is now AESimplementing integrated login internally. The third-party system provides an interface for receiving user information. The state-owned enterprise encrypts the user information with AES and transmits it to the third-party system through this interface, and the third-party system realizes the login operation by itself. It should be noted here that the key is very important, if 密钥丢失there is 信息泄漏a risk.

encryption salt

  1. Encrypted salt is also a concept that is often heard. Salt is a random string used to concatenate with our encrypted string for encryption.

  2. Salting is primarily used to provide security for encrypted strings. If there is an encrypted string after adding salt, the hacker uses the encrypted string through certain means, and the plaintext he gets is not the string before we encrypt it, but the string combined with the string before encryption and the salt. Said to increase the security of the string.

online encrypted website

  1. Webmaster Tools
  2. online encryption
  3. Java develops encryption and decryption tool classes to see my article

Summarize

Some recommended encryption algorithms are:

  1. Irreversible encryption: SHA256, SHA384, SHA512 and HMAC-SHA256, HMAC-SHA384, HMAC-SHA512

  2. Symmetric encryption algorithm: AES, 3DES

  3. Asymmetric encryption algorithm: RSA

reference

  1. Commonly used encryption algorithms
  2. Analysis of the five most commonly used Java encryption algorithms
  3. https://juejin.cn/post/6844903638117122056#heading-3

Guess you like

Origin blog.csdn.net/u011738045/article/details/120551399