crypto-js 引入
时间: 2023-10-14 17:03:57 浏览: 99
matplotlib-3.6.3-cp39-cp39-linux_armv7l.whl
您可以通过以下步骤引入crypto-js库:
1. 在终端中运行以下命令来安装crypto-js库:
```
npm install crypto-js --save-dev
```
或者使用淘宝镜像
```
cnpm install crypto-js --save-dev
```
2. 在代码中导入crypto-js库,并添加加密解密方法,代码示例如下:
```
'use strict'
import cryptoJs from 'crypto-js'
let keyOne = '313233343536373a'
export default {
// 加密函数
jiami (word) {
console.log(word)
console.log('秘钥长度为:', keyOne.length)
let key = cryptoJs.enc.Hex.parse(keyOne)
let enc = ''
if (typeof word === 'string') {
enc = cryptoJs.AES.encrypt(word, key, {
mode: cryptoJs.mode.ECB,
padding: cryptoJs.pad.Pkcs7
})
} else if (typeof word === 'object') {
let data = JSON.stringify(word)
enc = cryptoJs.AES.encrypt(data, key, {
mode: cryptoJs.mode.ECB,
padding: cryptoJs.pad.Pkcs7
})
}
let encResult = enc.ciphertext.toString()
return encResult
},
// 解密函数
jiemi (word) {
console.log('传入的密文:', word)
let key = cryptoJs.enc.Hex.parse(keyOne)
let dec = cryptoJs.AES.decrypt(cryptoJs.format.Hex.parse(word), key, {
mode: cryptoJs.mode.ECB,
padding: cryptoJs.pad.Pkcs7
})
let decData = cryptoJs.enc.Utf8.stringify(dec)
return decData
}
}
```
3. 现在您可以在项目中使用crypto-js进行加密解密操作。
引用资料:
<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [vue 中引入cryptoJS](https://blog.csdn.net/weixin_33734785/article/details/93660857)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文