安裝依賴
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>
對(duì)象
<script>
let obj = '需要加密的對(duì)象'汛聚;
let Message = JSON.stringify(obj)搓劫;
let key = '密鑰'粟瞬;
let hash = CryptoJS.HmacSHA256(Message, key).toString();
document.write(hash);
</script>