安装依赖
npm install crypto-js
在文件中引入
import Cryptojs from 'crypto-js'
字符串加密
<script>
let Message = '需要加密的字符串';
let key = '密钥';
let hash = CryptoJS.HmacSHA256(Message, key).toString();
document.write(hash);
</script>
对象
<script>
let obj = '需要加密的对象';
let Message = JSON.stringify(obj);
let key = '密钥';
let hash = CryptoJS.HmacSHA256(Message, key).toString();
document.write(hash);
</script>