怎样操作vue.js使用3DES加密
2018-08-24 16:22 rita_0204 阅读(2534) 评论(0) 编辑 收藏 举报如何在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)) |