当前位置:网站首页>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) 解密
边栏推荐
- After being "expelled" from bitland, the Jank group said for the first time: it will return as soon as possible through legal channels!
- MySQL学习 Day1 DDL、DML、DQL基础查询
- 数据库的常用命令1
- "Who is Huawei" documentary film series landing on BBC: exposing a large number of Ren Zhengfei's unknown experience
- 联发科首款5G SoC来了!A77+G77+APU3.0,11月26日正式发布!
- Deep learning - paper reading: action structural graph convolution network as-gcn
- 2021.8.9笔记 request
- Read only mode of buffer
- 江苏华存首发PCIe 5.0 SSD主控:台积电12nm工艺,2020年量产
- 展锐鲜苗:赋能全场景应用,海量数据需要AI与IoT融合
猜你喜欢

Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)
![[learning notes] the implementation principle of the ordered set Zset in redis - skip table](/img/c6/5d9f48fce1dc1c78b8c7dbcf046fc7.png)
[learning notes] the implementation principle of the ordered set Zset in redis - skip table

2. 改变颜色空间及颜色检测

2021.7.30笔记 索引

深度学习:GCN(图卷积神经网络)理论学习总结
![[mit 6.s081] LEC 1: introduction and examples notes](/img/5d/2fc4bde8eebbb22605d314b5292e05.png)
[mit 6.s081] LEC 1: introduction and examples notes
![[MIT 6.S081] Lab 9: file system](/img/f5/ea30b1fe5b6d73c86f2509c690ca20.png)
[MIT 6.S081] Lab 9: file system

View port PID and end process

MySQL学习 Day3 多表查询 / 事务 / DCL

zabbix6.0的安装部署
随机推荐
Common commands of database 1
How do corporate giants such as Schneider Electric and L'Oreal make open innovation? Uncover secrets of demo World Innovation Summit
[learning notes] solutions to hot account problems
Mysql四种锁
[MIT 6.S081] Lab 7: Multithreading
Deep learning: gat
Glory and Xiaomi reported on the double 11: they all called themselves champions
深度学习:GAN案例练习-minst手写数字
@Convert 注解在jpa中进行查询的注意事项
超实用!阿里P9私藏的Kubernetes学习笔记,看完直呼NB
Add music to the program interface and load background photos.
[mit 6.s081] LEC 6: isolation & system call entry/exit notes
2021.7.18笔记 mysql数据类型
[learning notes] Lombok's @builder annotation
Linked list storage structure of dynamic linked list 2 stack (linkedstack Implementation)
Deep learning: a survey of behavior recognition
On recommend mechanism in distributed training
Marvell公布旗下Arm服务器芯片路线图,下一代性能将比ThunderX2高两倍
[mit 6.s081] LEC 1: introduction and examples notes
2021.7.13笔记 子查询