Use of AES encryption Data transmission encryption and decryption processing---AES.js first step: Install crypto-js dependency in vue
Step 2: Create a new AES.js file in the static directory, for example: Step 3: Fill in the following code in AES.js import CryptoJS from "crypto-js"; // npm install crypto-js --save-dev //Randomly generate a specified number of 32-bit keys export default { generatekey(num) { let library = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let key = ""; for (var i = 0; i < num; i++) { let randomPoz = Math.floor(Math.random() * library.length); key += library.substring(randomPoz, randomPoz + 1); } return key; }, //encrypt(word, keyStr) { keyStr = keyStr ? keyStr : "CXMGNcYwTrtsadQmV935ONNXMUycpG1g"; //Judge whether ksy exists. If not, use the defined key var key = CryptoJS.enc.Utf8.parse(keyStr); var srcs = CryptoJS.enc.Utf8.parse(word); var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return encrypted.toString(); }, //decryptiondecrypt(word, keyStr) { keyStr = keyStr ? keyStr : "CXMGNcYwTrtsadQmV935ONNXMUycpG1g"; var key = CryptoJS.enc.Utf8.parse(keyStr); var decrypt = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return CryptoJS.enc.Utf8.stringify(decrypt).toString(); } }; Step 4: Introduce where encryption is needed
Step 5: Call //If it is an object/array, you need to convert it into a string by JSON.stringify first //Call the encryption method var encrypts = AES.encrypt(JSON.stringify(cars),keys); //Call the decryption method var dess = JSON.parse(AES.decrypt(encrypts,keys)); console.log(encrypts) console.log(encrypts.length) console.log(dess) This concludes this article on the detailed steps of using AES.js in Vue. For more relevant content about using AES.js in Vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed analysis of several situations in which MySQL indexes fail
>>: Docker nginx implements one host to deploy multiple sites
As the data stored in the MySQL database graduall...
1. Add a comment block at the beginning of the sty...
1. Concurrency Concurrency is the most important ...
As shown below: update table1 as z left join tabl...
When we preview PDF on the page, some files canno...
Table of contents 1. Set Deduplication 2. Double ...
There are many tasks to be done in search engine o...
Today we will implement a fragmented image loadin...
max_allowed_packet is a parameter in MySQL that i...
In the vue scaffolding, we can see that in the ne...
The Raspberry Pi model is 4b, 1G RAM. The system ...
The core is mysqldump and Runtime The operation i...
Preface In daily development, when we use MySQL t...
1. Write a backup script rem auther:www.yumi-info...
SVG has been widely used in recent years due to i...