1 Star 0 Fork 13

哈士旗/robot-tools

forked from vnool/robot-tools 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rsa.js 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
yooge 提交于 2020-11-23 02:10 . first commit
const NodeRSA = require('node-rsa');
var key = new NodeRSA({
b: 512
});
// key.generateKeyPair();
// console.log(key.exportKey('pkcs8-public'));
// console.log(key.exportKey('pkcs8-private'));
var publicKey =
`-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqwEDC2qq+Dg4nwGA+svd
Nr/Dg4Op1vXeD5H00/4J2KxBplfhc9cexGoisRVcH/GyhjPQtynn79ybWfCo5DxR
SiSIoqeB4//JG5c8zsuTaqaKbcyfQjlRelYABRGyqm8cRApg4ZVx6Or7+1AsIMLK
DzykHGCPxww/P00S9NhuKOEak8KXvjtNPUCq+5OMPHBVlYJgMrrfRlRTf87COdA3
Th743Ov2z5kh+V1wPiWU6htXXLA1biXWY0mveXFZIxrz3T2ji6LuZMg0rv9bOhSF
yQFqrP1THLAG2khcLK78muMMFkFMMHBv1Odms1XXpgOn9eMClMRqMCgwfGQ6mlL5
CwIDAQAB
-----END PUBLIC KEY-----`;
var privateKey =
`-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCrAQMLaqr4ODif
AYD6y902v8ODg6nW9d4PkfTT/gnYrEGmV+Fz1x7EaiKxFVwf8bKGM9C3Kefv3JtZ
8KjkPFFKJIiip4Hj/8kblzzOy5NqpoptzJ9COVF6VgAFEbKqbxxECmDhlXHo6vv7
UCwgwsoPPKQcYI/HDD8/TRL02G4o4RqTwpe+O009QKr7k4w8cFWVgmAyut9GVFN/
zsI50DdOHvjc6/bPmSH5XXA+JZTqG1dcs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3t80/NwQoWDWMxjNhp3yQ6S+YNNd4jtPdCN9F5lOQK+4Noy1rez0skLi7siB
81l4oH1t6CC0Tws1mXpu9yqxq/hcBy3kVu8ofdiipQKBgQCEGQ7TSyz1FaOPQhId
fQm200ToubheG4T4WHxBUWttirSmDepvW+jWHq/qlDzTSoA27c2gHZhJFHay42C7
scN3MeZD1XthDqgglldaYYxH3Qou3jxnhcL4uF3xgGFF24Wvs+/JetcnKoLklvpG
A5WABWxdq7rRDYwwC2gYxrQttQ==
-----END PRIVATE KEY-----`;
key = new NodeRSA();
key.importKey(publicKey);
//key.importKey(privateKey);
// const text = 'Hello RSA!';
// const encrypted = key.encrypt(text, 'base64');
// console.log('encrypted: ', encrypted);
// const decrypted = key.decrypt(encrypted, 'utf8');
// console.log('decrypted: ', decrypted);
module.exports = {
privateKey,
publicKey,
encode: function(text) {
return key.encrypt(text, 'base64');
},
decode: function(encrypted) {
return key.decrypt(encrypted, 'utf8');
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhong_fang_ying/robot-tools.git
git@gitee.com:zhong_fang_ying/robot-tools.git
zhong_fang_ying
robot-tools
robot-tools
main

搜索帮助