gpt4 book ai didi

node.js - Node rsa : InvalidAsn1Error: encoding too long

转载 作者:太空宇宙 更新时间:2023-11-03 23:40:26 25 4
gpt4 key购买 nike

我正在使用node-rsa模块来解密 key 。

我使用以下命令从 p12 文件创建了一个私钥

openssl pkcs12 -in xxx.p12 -nocerts -out privateKeyPkcs12.pem

它给出了 rsa 私钥,所以我尝试使用这个 rsa 私钥来创建 key ,如下所示

var NodeRSA = require('node-rsa');
var pemStr = '-----BEGIN RSA PRIVATE KEY-----\n' +
'ud5iSK4hAZo9DRi3/Xj7tYCb+AOv1rCAxWbM9KW959DaAYzO9eHRcmbO1Gusa93y\n' +
'2usgD3YYlfHAEvtMhW3KxDWXv0o/YE71pjltpn46qP0n2s78RwdbHONlXB0wk54Z\n' +
'1MqqZ8wxo/6mAu+ZqdCMe5rgOdMkXcHbFP+GFZQNSIoCrEQP098jhot9cYjyYNuW\n' +
'a7Y59gUEZE5s0jdrga/DcP+BUOfIoTZCf7gPqLQawjPXSp7Ddr5AxyVO8Phyp5yN\n' +
'hcdQV1Fvms5K7rsLvp0KFRz1iclrvBB5rYgawBSPGmrtP+AvRvjuDgfQiAPEA4SP\n' +
'cNx0oQ94q3jEPlhve86zhb1xDV4xnH8TKPYgpoafo6VC+w46FmoUh5/ZuKCsjBkV\n' +
'5gt3WyjsR5Jjgkv2pyH2rDfsB40DLvOg3GkgFo2gQ/UeXM3wQCjXRcG/rrlRYlj1\n' +
'9h+EjYaZE6vv+FpMLsYJc54bli/VjqyucEvvd0RuV15AEMI8cqwxlE3+ED2pv1Mk\n' +
'kLfONCAwylrvXBkapcp9P2qtRVLbyAzMXDJGDcSdxQFbDmmn8L/gOQs2+vgyvGet\n' +
'HxPC6gt1i6WEZHeQkSD68cs54JYmGZvu2bOTSCAMVOCKLv/Ed1LvSeowYZoHBXaK\n' +
'cRVqegBTWts5+DHWTwb8Nsrgz+5i6ZAFaJqGlrYjUApApDgAxTP5XQ47CxvtSg/T\n' +
'H25IJkY3Oz+7K18V1eslEk0bA44vYqeXia1ZLvLXRbtdSMlm0Fp7zTs7USVTJEgx\n' +
'RAGT8LnncwtZOFpEAYyIakI5lhe3aTvsDkW3pTXxDREKA2pmf0N7YAOw84tnoX8o\n' +
'w6hExfFrp2w82wRKft/ymoU5KUk6JSiHnuTu3JQPk/b9Vfb5zwRf5qXlLBERtO9U\n' +
'gctP2c3wvmF1pko8TfghKiTrAKi0Dft3Jrh50VDkmiFJCkupTDQ0EYyA4OV8PWui\n' +
'QhLFSGcBSGaik+7CMrh4TAiM59Hmh0Q3gKjmbvdYlx8gfZQzKWo71MkhDnbYTVnP\n' +
'6LU47Zo7ESFAPLFxBj0nTjJ8A7sFpQys/GK/fY29MnnR3LDT78zParNBKo56nCR4\n' +
'Sk8kL16Wx9hnTfEskHUKTmH9mph8hcv1S6/CQjQYVtLW13nlmGeAiJ/mf0sSzRhH\n' +
'mW5aCq3LAULIEpV0zRvpghZq4lc7RBbOudAgONrURWOgTgUxZ+N5PRMaesaeihpO\n' +
'gPY0LWyzb7CicK9y24oHO2uY87hinprusHaq/Rp4mVsYKRG0sk0/26bkbwn3sFMB\n' +
'LSSyGj32PD272bva1NE/4iWO+zppLKnroqUwrivmR3SPndvCX22x1qUiSY/R5UHp\n' +
'mcDWo9g9+nfPnXKmK2rwq82B4E+tqQZ68Iha95SaPYMt4pv+QPtaePxwSSpNPT9F\n' +
'WPwpEfKXa8wN9OAaGJBB9AM/Ry2aOTrekjNUxMzSqJdoBxsWxI0HrgVVaRQSk3VV\n' +
'juYMJdEjoSLY43jgZLEypA8ddmC55n/3Nwwyd6lkhvvkY+tvv6KL/zFnRQ81L0dP\n' +
'WTwvd33YSA6cCo4OEFixkls0lFq/MvesdXWZEyjNYzTlPYjqL9jIeik7VxQsw6sh\n' +
'-----END RSA PRIVATE KEY-----\n';

var key = new NodeRSA(pemStr);
console.log(key);

但是我收到了这个错误

   throw newInvalidAsn1Error('encoding too long');
^
InvalidAsn1Error: encoding too long
at module.exports.newInvalidAsn1Error (c:\Users\prabu\Desktop\project\node_modules\node-rsa\node_modules\asn1\lib\ber\errors.js:7:13)
at Reader.readLength (c:\Users\prabu\Desktop\project\node_modules\node-rsa\node_modules\asn1\lib\ber\reader.js:94:13)
at Reader.readSequence (c:\Users\prabu\Desktop\project\node_modules\node-rsa\node_modules\asn1\lib\ber\reader.js:127:16)
at NodeRSA.module.exports.NodeRSA.$loadFromPrivatePEM (c:\Users\prabu\Desktop\project\node_modules\node-rsa\src\NodeRSA.js:86:16)
at NodeRSA.module.exports.NodeRSA.loadFromPEM (c:\Users\prabu\Desktop\project\node_modules\node-rsa\src\NodeRSA.js:65:18)
at new NodeRSA (c:\Users\prabu\Desktop\project\node_modules\node-rsa\src\NodeRSA.js:35:18)
at Object.<anonymous> (c:\Users\prabu\Desktop\project\server.js:30:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)

如何创建 key ?

最佳答案

删除键字符串末尾的换行符 (\n)

'-----END RSA PRIVATE KEY-----\n';

'-----END RSA PRIVATE KEY-----';

关于node.js - Node rsa : InvalidAsn1Error: encoding too long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24631093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com