当前位置:网站首页>rsa加解密(兼容微信小程序环境)
rsa加解密(兼容微信小程序环境)
2022-07-27 16:11:00 【mr_cmx】
1、安装
npm i wxmp-rsa -S
2、创建一个js文件作为之后可复用的工具库,内容如下:
import {
JSEncrypt } from 'wxmp-rsa'
// 定义公钥 这里要改为你自己的公钥
const publicKey = ` -----BEGIN PUBLIC KEY----- MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgFnWSUwsmGawhMJ30z6y5li2jcf1m7rPMZcwZOS3To8bk3OBaMGhVEc1F8GtJBbc1rn/HCLNL9zrCy21EefJON8tRFcYHnpseZSzh+349lIhS+MFw9x4JUddwSPDyxwha929cKzMuVoftu3CJ+kqDBVvxLk7iDBzUMqW3Kgehk2TAgMBAAE= -----END PUBLIC KEY----- `
// 定义私钥 这里要改为你自己的私钥
const privateKey = ` -----BEGIN RSA PRIVATE KEY----- MIICWgIBAAKBgFnWSUwsmGawhMJ30z6y5li2jcf1m7rPMZcwZOS3To8bk3OBaMGhVEc1F8GtJBbc1rn/HCLNL9zrCy21EefJON8tRFcYHnpseZSzh+349lIhS+MFw9x4JUddwSPDyxwha929cKzMuVoftu3CJ+kqDBVvxLk7iDBzUMqW3Kgehk2TAgMBAAECgYBRChPeyk/EOrHX912xLpLKLguh+LY9g1B50ScChzUvtTGDPZaxLQYoogVHKhfnI9nzuOS5pBzsDX9tAO0hCQzqfHgqRjn+vEgm1Ui+f0E3BVRnhobcJKZpZqlvCBR5Gu2+zlrY4SeGq3AuQSr/A5FiB5k0RgsvNycDTjqyg7TXGQJBAJoZ8Yr0zakxT1I8lVqsFbeNPtt8FNG2UgIlIs9RL7aXhw+Y3sWtk/kbaOXafSofu0NcQYx4Km3M3kiPlcNfTJ8CQQCVPcaRpu+mprRgHS6s76Z668NaFsjX04CUUa0kCrey+Nf/SJJ3BkRHM7GllZWuI/RSXs/F5N38p5bfkn7QZqaNAkBy3dHJZW8DpgjdYOFnhAxwFK39BwGxzHhWtv26kWbCcTKwsp+jtB4vunm3k+RmiN6aeGM35L6jt+kdJ0JYLmo7AkBJpRZbwZj5D8Jqu3vQ8uGgPr9DsYKinkgQ6M0bv/4uXwWXf+Rmv7zpteSv5UTbjfp+uzKkYO/6QWj+InhZto3xAkAOA0i702dLHm5elLWvht7UEYIDEW1+rYGdbthmJBvT9sZhVKL954Y9hDzBWepjYsBiJnmIkgeladPnU5025/G/ -----END RSA PRIVATE KEY----- `
const myEncrypt = new JSEncrypt()
myEncrypt.setPublicKey(publicKey)
myEncrypt.setPrivateKey(privateKey)
class rsaCode{
encryptLong(data){
//加密
let datajson;
if(typeof data !=="string"){
datajson=JSON.stringify(data)
}else{
datajson=data
}
const cryptStr = myEncrypt.encryptLong(datajson)// 对需要加密的数据进行加密
return cryptStr
}
decryptLong(cryptStr){
//解密
const originalStr = myEncrypt.decryptLong(cryptStr)
return originalStr;
}
}
export let rsa=new rsaCode();
3、在需要rsa加解密的组件使用工具
import {
rsa} from '../../utils/rsaCode';
const cryptStr=rsa.encryptLong('要加密的内容')
//rsa.decryptLong(cryptStr) 解密
边栏推荐
- 深度学习:STGCN学习笔记
- Software installation related
- 深度学习:GAN案例练习-minst手写数字
- [MIT 6.S081] Lec 5: Calling conventions and stack frames RISC-V 笔记
- 1542. Find the longest super substring hash + state compression
- 嘉楠耘智已完成预路演,预计11月20日登陆纳斯达克
- 深度学习:GCN(图卷积神经网络)理论学习总结
- [MIT 6.S081] Lab 10: mmap
- The end of another era!
- Linked list storage structure of dynamic linked list 2 stack (linkedstack Implementation)
猜你喜欢

GIS数据漫谈(五)— 地理坐标系统

Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?
![[MIT 6.S081] Lec 8: Page faults 笔记](/img/e2/0f5332dd9d2b439bcf29e87a9fa27f.png)
[MIT 6.S081] Lec 8: Page faults 笔记
![[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6](/img/ca/e8c0827b13805c7c74cc41bf84c6ff.png)
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6

Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)
![[MIT 6.S081] Lec 3: OS organization and system calls 笔记](/img/34/073d00245eb39844bbe1740f65fe07.png)
[MIT 6.S081] Lec 3: OS organization and system calls 笔记

View port PID and end process

二叉树概念
![[MIT 6.S081] Lab 5: xv6 lazy page allocation](/img/f6/8b619412bc6ba425d0f04629917e80.png)
[MIT 6.S081] Lab 5: xv6 lazy page allocation

深度学习:GAT
随机推荐
2021.7.18笔记 mysql数据类型
[MIT 6.S081] Lab 5: xv6 lazy page allocation
How do corporate giants such as Schneider Electric and L'Oreal make open innovation? Uncover secrets of demo World Innovation Summit
Software installation related
C杂讲 链表初讲
The first PCIe 5.0 SSD master of Jiangsu Huacun: TSMC 12NM process, mass production in 2020
[learning notes] classification of locks in the database
数据库的常用命令2
华为Mate30 Pro 5G拆解:自研芯片占比过半,美系芯片依然存在!
深度学习-论文阅读:动作结构性图卷积网络AS-GCN
JRS-303用法
GIS数据漫谈(五)— 地理坐标系统
1. opencv图片基础操作
MySQL four locks
@Datetimeformat received less than minutes and seconds, conversion times type exception
XML学习 Day1 : xml / Jsoup解析器 / selector选择器 /Xpath选择器
Marvell announced the roadmap of its arm server chip, and the performance of the next generation will be twice that of thunderx2
《华为是谁》纪录短片集登陆BBC:曝光大量任正非不为人知经历
深度识别:论文阅读_2S-AGCN CVPR2019(基于骨架的动作识别的两流自适应图卷积网络)
Guoju spent $1.8 billion to acquire its competitor KEMET, and the transaction may be completed in the second half of next year