Several common encryption methods:

  • Symmetric encryption algorithm: AES
  • Asymmetric encryption algorithm: RSA
  • Hash algorithm: MD5

First, symmetric encryption algorithm

AESencryption

Symmetric encryption (also known as private key encryption) is an encryption algorithm that uses the same key for encryption and decryption.

Features:

  • Advantages: open algorithm, small amount of calculation, fast encryption and decryption, high encryption efficiency
  • Disadvantages: the encryption side and the decryption side share a key, once the key is leaked, it is not safe.
  • Application scenario: Local mass data encryption, HTTPS communication, and network transmission

JS AES encryption library: crypto- JS

Note: With crypto-js, the introduction of 4.x.x will cause the package to become too large after the project is packaged. For example, there are strict restrictions on the volume of dependent packages. It is recommended that the version be downgraded, such as 3.1.9, which will be much smaller when packaged.

Asymmetric encryption algorithm

RSAencryption

Asymmetric encryption algorithms require two keys: a publickey and a privatekey. The public key and private key are a pair. If the public key is used to encrypt data, only the corresponding private key can be used to decrypt data. Because encryption and decryption use two different keys, the algorithm is called asymmetric encryption.

Features:

  • Advantages: Asymmetric encryption is more secure than symmetric encryption.
  • Disadvantages: Encryption and decryption takes a long time, slow speed (processing large amounts of data is really slow), only suitable for a small amount of data encryption.
  • Usage scenario: Encryption and decryption takes a long time and is slow. Therefore, it is suitable for encrypting only a small amount of data.

JS RSA encryption library: jsencrypt

Note:

A smaller cryptographic library is recommendedwxmp-rsa, will be very useful in doing wechat small programs and other development with strict requirements on project volume.