由第三方推送过来的加密信息密匙是用RSA4096加密,找了很多js或unicloud上的rsa加解密,大多数是2048位。请问哪位大神能提供一个基于前端js或unicloud的rsa4096的解密模块?
虚渺
- 发布:2022-08-15 02:10
- 更新:2022-08-15 16:06
- 阅读:665
虚渺 (作者)
crypto好像有,但怎样引用?这第一句就出错了:const { generateKeyPairSync } = require('crypto');
2022-08-16 16:35
DCloud_uniCloud_WYQ
回复 m***@163.com: 错误是什么?
2022-08-16 17:18
虚渺 (作者)
回复 DCloud_uniCloud_WYQ: 用const crypto = require('crypto');就可以。不过后面不会用了,大神有没有参考资料?
我想实现就是提交一个rsa4096加密的字符串,返回解密结果;也就是说函数只需要解密,私匙直接放在函数里面。
2022-08-17 11:19
DCloud_uniCloud_WYQ
回复 m***@163.com: 搜 nodejs privateDecrypt
2022-08-17 14:42
虚渺 (作者)
回复 DCloud_uniCloud_WYQ:
你好,我用的测试代码如下:
'use strict';
exports.main = async (event, context) => {
var reqData=event.queryStringParameters;
if(reqData==null || reqData.msg==null) return "";
};
执行后提示
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line Error: error:0906D06C:PEM routines:PEM_read_bio:no start line at Object.publicEncrypt (crypto.js:390:12) at Object.exports.main (/var/user/__index.js:19:25) at y (/var/user/index.js:1:8617) at EventHandler.exports.main [as realHandler] (/var/user/index.js:1:9854) at EventHandler.handle (/var/runtime/node8/bootstrap.js:427:28) at invoke (/var/runtime/node8/bootstrap.js:225:22) at Timeout.setTimeout [as _onTimeout] (/var/runtime/node8/bootstrap.js:150:9) at ontimeout (timers.js:475:11) at tryOnTimeout (timers.js:310:5) at Timer.listOnTimeout (timers.js:270:5)
我估计是public key格式问题,但不知道正确应该怎样,请大神指点迷津。
2022-08-19 10:44
DCloud_uniCloud_WYQ
回复 m***@163.com: 你公钥换行没了
2022-08-19 16:14
虚渺 (作者)
回复 DCloud_uniCloud_WYQ:
谢谢大神。加密后问题又来了,解密时提示error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong。
代码如下:
'use strict';
const { RSA_PKCS1_OAEP_PADDING, RSA_PKCS1_PADDING } = require('constants');
exports.main = async (event, context) => {
var reqData=event.queryStringParameters;
reqData.msg="rlxuLAhYW1VHHQEhrgFquUVUbLthHnPGr8LYz4Ft/t3TNPHrwWFMW1ZIOhPpEOP9ZqRefGP4K8MQ+8onBfkg0e/pUR3N0OunG/VE0e5ONlj4YN4ziUlX0SV+x9J8CVH2anpwX/DVsoZNx7WTuf9H1mXNp8Vzh3cHqkvhG8kPk4/CQJbdzVZBeef37lK9K8ecp3t+w87ZjirFDeWXK/LjNphpBzlT7Z+ExP+RF/ARqr/tm/jeqtZIq29BgBO+KGRfdI2qXHhslk9+c+Pwr9oPIrRnA6oNNf0nA6ArdcWUjOnwMUGK56tTgFlFzStQMTRGiYqUUmuScaoUfs3Xb8ez1gbg2RzEZb4nJbyM5Bpe3DTJFJrs8DoHgCgiaM2OLYa37OiPGLSVndwFKyk1kgKHP6mrHxeUir9j8Hwh5NNv3h1/N3L+9EohB8xeTj+Lcy6gmw/Jq4DtACcuerQiQHRjYn4NXF/OqZ6qLV9EO7XfsXyFqEFkH6a1arXvjLurb984W8MM05PhUXEzmzIWh1u4CsPMwmutVd0QmRleRtMeewbWsU9B1t2ZTE05EedMFN8Gbb27K/V7wlYdBkZVG2UfgqIaxsub+KLYORRDYH4dRN5JDJPAyNt7/hV+b2du3TbL23+P2u/pwrKaC/Vxs4ger4ES313rB/IYl5/h02O21Mk=";
if(reqData==null || reqData.msg==null) return {flag:-1,msg:"No decrypt message."};
var pKey="-----BEGIN RSA PRIVATE KEY-----\r\n"+
"MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDGuC24UFmyMMeO"+
"IPHgSIsrcmH+3KXY9W1yl1v2OEJ4cCERdwB2zsTnin/alZMjUmb0smabjR9z+INP"+
"Ml0yLRWL/u/jkP025LsRT3Q4c2FjzmwTaUNr/geTVubQAneCK4iSR50WWv1VAIZF"+
"tD2uEMFebmdTj5hScojkucyOJJnF7uYeybQR0c1GhwXqboRFPCS+KUk4CP8ZQfVJ"+
"XeRsrUqu1S9gAdrS4cyhs5pX5Orn2tjsjKBtfT4XXfpM34O3fHwenVdMfQPLf3+y"+
……省略40行……
"jB0Jj+WXbYHaBJS0OhQmC5xUTz3V7YHs6urvZtH3UmdvfJDde12TrdFJKcFit7zl"+
"K41fQO2gl8tDsWU/GxUOGA1eTYe3BCwYEzgncmPvWip11NVn+JbSKrvAVE3iWuW3"+
"PbiXpk2062U2LpxITYtuanatgNpv3lak+xYcR2ucqxfRc7bp2DxiFuJwWrwt2OOc"+
"x3V+IUuRgR0KbM1dz7UatoCPVm/k+SgqkDsxCw1++CThohfoWkzDxCwvm6GT5C5a"+
"E2Q3tQv61bwGq34xf86zEp685S2mOQ=="+
"\r\n-----END RSA PRIVATE KEY-----";
var pKeyOption={
key:pKey,
constants:RSA_PKCS1_PADDING
};
var _buffer=Buffer.from(reqData.msg,'base64');
};
2022-08-22 14:15