fucking-util-signature-uni
兼容支持 微信小程序
模块依赖 fucking-util 模块, 请预先安装
模块选择
- 要使用
uni-app
模式开发, 使用fucking-util-signature-all
- 不使用
uni-app
模式开发h5
或web
或mui
项目 (window自带crypto模块) 或node
环境使用fucking-util-signature
- 小程序使用此模块
使用方法
// 多选一var Signature = ; // 生成公私钥 pkcs #8 (需要其它版本可以提issue)let publicKey privateKey = SignatureRSA; console; // RSA对象let rsa = ; // 设置公私钥rsa;rsa; let unsigned = 'hello world!'; // 字符串签名let sign = rsa; console; // 签名验证let verified = rsa; console; let unencrypt = 'Unencrypt string'; // 字符串加密let encrypted = rsa; console; // 解密let decrypted = rsa; console;
高级用法
let keys = SignatureRSA; let signature = ; let rsa = signature;// let md5 = signature.md5 ( );// let sha256 = signature.sha256 ( ); let unsigned = 'hello world!'; let sign = rsa // 更新源数据 // 设置私钥; // 生成签名 console; let verified = rsa // 更新源数据, 此处可以忽略 // 设置公钥; // 验证签名 console;
对象签名/验签
对象签名模式是先把对象转成querystring
, 对象内的json
内容会被转成JSONString
, 然后再加上签名类型字段, 有盐的话会加盐字段, 最后进行字符串签名.
let signature = ; // 默认的 formOptions, 可以不用设置signatureformOptions = signKey: 'sign' // 放置签名的字段 signTypeKey: 'signType' // 放置签名类型的字段 signSaltKey: 'key' // 盐值字段 ignoreKeys: // 签名忽略的字段 'sign' 'key' salt: "" // 盐; let signer = signature;// let signer = signature.rsa ( ); let form = user: "1589235" userInfo: nickname: "Liping Ruan" avatar: "@%FFOISJAFJZC" ; let sign querystring = signerform true // 设置 签名/验签 为对象签名模式; // 签名输出 16进制 字符串 console; let verified = sha256; console;
formOptions
加盐和自定义 let signature = ; let formOptions = signatureformOptions; formOptionssignKey = 'SIGN';formOptionssignTypeKey = 'SIGN_TYPE';formOptionssignSaltKey = 'SIGN_SALT';formOptionsignoreKeys = 'SIGN' 'SIGN_SALT' ;formOptionssalt = "Default salt"; // 默认盐, 可以不设置 let json = a:1b:2 ; let signer = signature; let sign querystring = signer; console;console;console; let verified = signer; console;