如何在VUE-CLI手脚架建立的工程中使用3des加密:
|
1
|
npm install crypto-js --save-dev |
|
1
|
import CryptoJS from ‘crypto-js‘ |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
//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)) |
原文:https://www.cnblogs.com/rita-0204/p/9530576.html