This time I will show you how to use 3DES encryption to operate vue.js, and what are the precautions to use 3DES encryption when operating vue.js. The following is a practical case, let's take a look.
How to use 3des encryption in a project created by VUE-CLI scaffolding:npm install crypto-js --save-dev
import CryptoJS from 'crypto-js'
//DES加密 Pkcs7填充方式 encryptByDES(message, key){ const keyHex = CryptoJS.enc.Utf8.parse(key); const encrypted = CryptoJS.DES.encrypt(message, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return encrypted.toString(); } //DES解密 decryptByDES(ciphertext, key){ const keyHex = CryptoJS.enc.Utf8.parse(key); // direct decrypt ciphertext const decrypted = CryptoJS.DES.decrypt({ ciphertext: CryptoJS.enc.Base64.parse(ciphertext) }, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return decrypted.toString(CryptoJS.enc.Utf8); } const _key = 'abcdefghijklmn' const _password = '123456' //加密 console.log(this.encryptByDES(_password,_key)) //解密 console.log(this.decryptByDES(_password,_key))
Detailed explanation of the steps for getting started with vuex
Detailed explanation of the optimization steps using vue-admin-template
The above is the detailed content of How to operate vue.js to use 3DES encryption. For more information, please follow other related articles on the PHP Chinese website!