vue使用国密sm2加密解密
程序员文章站
2022-06-06 21:17:52
...
# 安装依赖
npm install --save sm-crypto
# 解密方法decode() {
const sm2 = require('sm-crypto').sm2
const cipherMode = 1 // 1 - C1C3C2,0 - C1C2C3,默认为1
// 私钥
var priKey = "66c4aec7383fb68ef5d280bd868809d086fd397d3a61a170e63fdbe59e0a9102";
// 密文
var encryptData = "e8fa2be4adec9bbb4084576864988b4993826d0f61f7110ff80c1aa02d8bbe162abf65fcb1df4c3988d4132a3c554d61e953f43777d98a455feda5b29cc453f2245771f8f5d1ae2a529e6dcdb7103f446a89b243be0d50e3cb4549c1cb6f3769347d3d36c333017551e366d214d574b7";
// 解密结果
let decryptData = sm2.doDecrypt(encryptData, priKey, cipherMode)
console.log(encryptData)
console.log(decryptData)
}