In business systems, it is usually necessary to encrypt the user's password and then send http requests. Strengthen security verification of system login.
Common encryption methods include MD5, Base64, CryptoJS AES DES, etc. The following is a few encryption methods I often use:
MD5 encryption
1. Install module ts-md5
$ npm install ts-md5 --save
2. Use md5 for encryption
import { Md5 } from 'ts-md5'; // ... // passwordpassword: string = "12345"; // Encryption method - md5 encryptiondecode() { const passwordMd5 = ().toString(); // Result: 827ccb0eea8a706c4c34a16891f84e7b}
Base64 encryption
1. Install module js-base64
$ npm install js-base64 --save
2. Use md5 for encryption
import { Base64 } from 'js-base64'; // ... // passwordpassword: string = "12345"; // Encryption method - Base64 encryptiondecode() { const passwordBase64 = (password); // Result: MTIzNDU=}
DES encryption
DES symmetric encryption is a relatively traditional encryption method. Its encryption and decryption operations use the same key key. When the sender of the information and the receiver of the information transmit and process the information, they must jointly hold the password (called a symmetric password). It is a symmetric encryption algorithm.
crypto-js Github: /brix/crypto-js
1. Install the module crypto-js
$ npm install crypto-js --save
2. Use DES for encryption
import CryptoJS from 'crypto-js'; // ... // Keykey: string = "abcdefg"; // passwordpassword: string = "12345"; // Encryption method - des encryptiondecode() { // key encoding const keyHex = .(); (()); // Result: 61626364656667 // Encryption const passwordDES = (, keyHex, { mode: , padding: .Pkcs7 }).toString(); (passwordDES); // Result: zYGeIdaZpEM=}
3. Encryption using AES
The encryption usage is basically the same as des.
import CryptoJS from 'crypto-js'; // ... // Keykey: string = "abcdefg"; // passwordpassword: string = "12345"; // Encryption method - des encryptiondecode() { // Encryption const passwordDES = (, ).toString(); (passwordDES); }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.