//des 加密
encryptByDESModeCBC(ciphertext2, keyItem,ivItem) {
const key = CryptoJS.enc.Utf8.parse(keyItem); //16位
const iv = CryptoJS.enc.Utf8.parse(ivItem); //16位
let encrypted = '';
const srcs = CryptoJS.enc.Utf8.parse(ciphertext2);
encrypted = CryptoJS.DES.encrypt(srcs, key, {
iv:iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return CryptoJS.enc.Hex.parse(encrypted.ciphertext.toString());
},
//des 解密
decryptByDESModeCBC(ciphertext2, keyItem, ivItem) {
var keyHex = window.CryptoJS.enc.Utf8.parse(keyItem);
var ivHex = window.CryptoJS.enc.Utf8.parse(ivItem);
var decrypted = window.CryptoJS.DES.decrypt({
ciphertext: window.CryptoJS.enc.Hex.parse(ciphertext2)
}, keyHex, {
iv:ivHex,
mode: window.CryptoJS.mode.CBC,
padding: window.CryptoJS.pad.Pkcs7
});
return decrypted.toString(window.CryptoJS.enc.Utf8);
}
vue DES加密、解密
最新推荐文章于 2024-05-28 16:59:54 发布