vue使用sm2对手机号邮箱等加签名,数据完整性

发布时间:2024-01-09 17:56:25

vue使用sm2对手机号邮箱等加签名,数据完整性

1、安装依赖

npm install --save sm-crypto

2、在utils文件下新建sm2Util.js

// sm2Util.js
const SM2 = require('sm-crypto').sm2;
const publicKey = 'woshigongyao' // 公钥
const privateKey = 'woshisiyao' // 私钥


/* 
 * 加签工具函数
 * @param {String} text 待加签文本
 */
export function encrypt(text) {
  return SM2.doSignature(text, privateKey, { hash:true, der:true });
}

3、使用方法

使用方法可参考前端vue2使用国密SM4进行加密、解密:https://blog.csdn.net/qq_41838435/article/details/135223939

由于项目需要,这里只做了加签,验签差不多的

签名:sm2.doSignature(text, privateKey, { hash:true, der:true }))

验签:sm2.doVerifySignature(text, vSign, publicKey, { hash:true, der:true })

具体可参考 这里https://github.com/JuneAndGreen/sm-crypto

文章来源:https://blog.csdn.net/qq_41838435/article/details/135483650
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。