文件名称:wx加密解密js类库
文件大小:86KB
文件格式:ZIP
更新时间:2023-04-22 10:36:31
rsa 小程序 java
简要说明: 将 wx_rsa.js文件copy到自己想放置的目录下,并在需要用到的js文件中引用 如: var RSA = require('../../utils/wx_rsa.js') 2. 在对应的触发事件下进行相应的 加密: var input_rsa = this.data.input; var encrypt_rsa = new RSA.RSAKey(); encrypt_rsa = RSA.KEYUTIL.getKey(publicKey); encStr = encrypt_rsa.encrypt(input_rsa) encStr = RSA.hex2b64(encStr); console.log("加密结果:" + encStr) 解密: var decrypt_rsa = new RSA.RSAKey(); decrypt_rsa = RSA.KEYUTIL.getKey(privateKey); if (encStr.length <=0){ wx.showToast({ title: '请先加密', icon: 'loading', duration: 1000 }) }else{ encStr = RSA.b64tohex(encStr); console.log(encStr + "001--100") var decStr = decrypt_rsa.decrypt(encStr) console.log("解密结果:" + decStr) this.setData({ output: decStr }) } 加签: var sign_rsa = new RSA.RSAKey(); sign_rsa = RSA.KEYUTIL.getKey(privateKey); console.log('加签RSA:') console.log(sign_rsa) var hashAlg = 'sha1'; Sig = sign_rsa.signString("signData", hashAlg); Sig = RSA.hex2b64(Sig); // hex 转 b64 console.log("加签结果:" + Sig) this.setData({ output: Sig }) 验签: var verify_rsa = new RSA.RSAKey(); verify_rsa = RSA.KEYUTIL.getKey(publicKey); if (Sig == ""){ wx.showToast({ title: '请先验签', icon: 'loading', duration: 1000 }) }else{ Sig = RSA.b64tohex(Sig) var ver = verify_rsa.verifyString("signData", Sig) console.log('验签结果:' + ver) this.setData({ output: Sig }) }
【文件预览】:
app.js
project.config.json
utils
----util.js(481B)
----wx_rsa.js(441KB)
sitemap.json
README.md
pages
----index()
--------index.wxml(484B)
--------index.js(4KB)
--------index.wxss(1KB)
--------index.json(2B)
app.json
app.wxss