Look at the code first, just copy and use it. This is a relatively common scenario. We use the (crypto-es==>vue3) (crypto-es==>vue2) library.
If you are satisfied, please give Mo Chengchen a star
Encapsulate him as a separate js file
import CryptoJS from 'crypto-es'
export default {
encrypt(word, keyStr) {
keyStr = keyStr || '固定密钥'
const key = CryptoJS.enc.Utf8.parse(keyStr)
const iv = CryptoJS.enc.Utf8.parse('固定密钥')
const encrypted = CryptoJS.AES.encrypt(word, key, {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.ZeroPadding,
iv
})
return encrypted.toString()
},
decrypt(word, keyStr) {
keyStr = keyStr || '固定密钥'
const key = CryptoJS.enc.Utf8.parse(keyStr)
const iv = CryptoJS.enc.Utf8.parse('固定密钥')
const decrypt = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.ZeroPadding,
iv
})
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
},
}
transfer
import 名称 from 'CryptoJS路径'
created(){
this.password = 名称.encrypt(this.password)
}
Other related questions can leave a message.