0
点赞
收藏
分享

微信扫一扫

vue 里使用 crypto-js 实现 DES 算法加解密


参考CryptoJS文档

vue 里使用 crypto-js 实现 DES 算法加解密_crypto-js

代码

代码实现如下:

<template>
<div class='crypto-js'>
cryptoJs 测试页面
</div>
</template>

<script>import CryptoJS from "crypto-js";

export default {
data () {
return {
hashStr: "凯小默的英文名叫kaimo"
};
},
mounted() {
// 加密
const DES_hashStr = CryptoJS.DES.encrypt(
this.hashStr,
CryptoJS.enc.Utf8.parse("ABF"),// keyHex
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
} // option
).ciphertext.toString();
console.log('DES_hashStr', DES_hashStr);

// 解密
const DES_decrypt_hashStr = CryptoJS.DES.decrypt(
{
ciphertext: CryptoJS.enc.Hex.parse(DES_hashStr)
},
CryptoJS.enc.Utf8.parse("ABF"),// keyHex
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
} // option
).toString(CryptoJS.enc.Utf8);
console.log('DES_decrypt_hashStr', DES_decrypt_hashStr);
},
};</script>

效果

如图:

vue 里使用 crypto-js 实现 DES 算法加解密_DES 算法_02


举报

相关推荐

0 条评论