npm install crypto-js或者下载crypto-js的js文件引入
封装一个des.js
下载地址:
https://down.chinaz.com/soft/40271.htm
封装后在页面调用des.js文件里面的方法加密解密
// An highlighted block
// des.js
import CryptoJS from './crypto-js.js'
// 秘钥
export function getKey(){
return CryptoJS.enc.Utf8.parse('48CDAB')
}
// 偏移量
export function getIv(){
return CryptoJS.enc.Utf8.parse('0672DE')
}
/*加密*/
export function encrypt(data) {
const message = CryptoJS.enc.Utf8.parse(data);
var ciphertext = CryptoJS.DES.encrypt(message, getKey(), {
iv: getIv(),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return ciphertext.toString();
}
/*解密*/
export function decrypt(data) {
var bytes = CryptoJS.DES.decrypt(data.toString(), getKey(), {
iv: getIv(),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return bytes.toString(CryptoJS.enc.Utf8);
}
引入des.js
//引入des
import {
decrypt,encrypt} from '@/utils/des.js'
使用
// 页面调用 解密
this.hostIP = decrypt(json["siphost"]);