Node-rsa:无法解决编码时间过长的错误

时间:2018-10-22 16:12:38

标签: node.js encryption

我一直在尝试使用节点中的私钥解密数据。

    const key = "308204bc020100300d06092a864886f70d0101010500048204a6308204a202010002820101008b21b318a08f9f0c58d40f57e034a13f4becca18f6697bcd36f8f40fd2f36b46ccd8896d8b3dbb6638cd0c565e0123dc0155e01d44633e3d246e65ef3156f5091372645ad34b072969cc1941f06af206e4322ab234f38352a8dbe5416a376ca08870e8540a7fdbeeb517356526f6b60b87cde0f33dd94013cb83a16bc3785ea401cb29a36f356241d417a5e71a6e928805760cb06dbff3c17dd3e3799865e33d1e29b4b76aa7ce8bf0488dec913832c9d5a2d9b6758970e9f27df0d0bed2013dc4c2bcfbb0290b10552e1a2f0c77a53a15c9557efea2bdfa93833fb65347dae5c1c1b44b0673530b961f945b596893a4210d59b224ac44298dd8cac7313af637020301000102820100633a01950acde34cd6fd468411aef7614130fb619a3bd8c39ef5267b32a3d05a8a35d4ad7fa4e34620347d1c0ba71c8007a3cb569433836befd39c775ee4f995237d6dfd28bc55bb3f6d048676848f6042d754840c27affcffd8f4441710b834359af0d71f35d91101ae2fb2987b53921da4c34e3749fddd20441c97d2acc23175ecb3f217b95d4bacda1aa92c6e1066cb6911c4bc5c2307cf4b9a5f95f761659d6a79906b91ccebfe14b47465babe4892a58eae437250ff0ab897f8027ebc47c08300b5a21f1082d5193f1776b38de92de560c297533550b78f7c979b0240e056d8944424efa1f9c2cf76e28f5df3e38e8d5f0a019afff8eb46babf4b1371c102818100fa36776cf1ba4feb577932da7a5447e0c2550cb441926de2ceb0b87cca1eee37293425684ec4c1fd156aa8642946500d1ab73b4baffb6a5ba03f11b99025142aaf0d5b7287cd776f7cfb37a767985abf0cd72f89e0da115ce4e7d047464ce7dad44754b746821554290cf9d8a7a478faf9c6b97406dcb3877f735496dba89cdf028181008e5982e015ca8725dc37b3987331d1142b88c6123902ea144da04cbb1f58123329143180d01d8ab806bedc4270c1bb1bcec1fc4bb1a3088acbaa02c6ad60f9ebd20fe6628fb7c65b9ae60771118b1d8ada987667c8db616d373fb9cbc4f50348d7a6f63cc9e3d6ce1338306b37d7c294a23e291ba6a53514018f56ea15fa79a90281805497c78698af21c7f239f29c74d13bbfdc53bec8ce86800a3750fdfe8aa32c6c8fcca67cfe6c7d1d60793fd72531356d48c3fc1319bb497912d35fddb9c31f6f52e1943243818ec8ad9b8d74568ce6d942b119cc66adb34311cce1d8c706c7386f9e7220c880c04f44d5b33eb166e4d40d504770d7c5141952589e97a649fa470281800d640438ba340c1496abb2bc5391cb1e3f9e252bcfab2383f76d6dea685f6b8ede7d64cebe4519288891e9bc62490725ed84380c92d0485c6e1e3716a376acebef1dc9c959c5aae63123146e217d59b11731226a4eedbc337ef002b55578caef4e420985dc640f6fe144f6e10f26bfca259cfd56f98d2efa0bcf85188e2abac90281803ecbbbeb9bd76415f68f7cc6de5b8813a9a040dcacc61b969cf91d6ae213db3eca9535b1c62e95e83fc743b54ce868a47c239b798a275276f65601400f1f44f21609ce4f42cdec128262db20a691948128bfb046fb25219d0df997ad3a19eca3ab0e7c5802ead7ea459ad060f50c75b98ddbccf137435878976e5a36915f0cfe";
    const data = "LQyueVca+KW0L28IcpLny+3uZx1F1O3PP+eOlahbgumvScJaTq+CCFvKOGTgrYUgls3UVxVks/YuHcv4LpzTOUmjjSViLxoFMd/uzV6RIzNC7ONy3vLxqgY9qaG5tc1f2yakbnopL7dvE2w8GFRU5jqxz9UNOIctEFLYHk22WD6nfk1JDY5hqRJ8gheFjDrG2y91DdAzW9sVl8URWG1v17JtyN+ml+q/Hu+grtLjZaQgqlP3/rEV1TVWT9flwdmb08de02Tv/hsRKITf4VpPCCxTt4GksBHMHFbKtr7wibVty3PbbSwnPK6uTdoPU764zUR+mD+6rHdHgdEE80439A==";

    var NodeRSA = require('node-rsa');
    var private_key = new NodeRSA({bits:2048});
    var testKey = '-----BEGIN PRIVATE KEY-----\n'+key+'-----END PRIVATE KEY-----';
    private_key.importKey(testKey, 'pkcs1-public');

但是出现了这个错误。

    throw newInvalidAsn1Error('encoding too long');
  ^

    InvalidAsn1Error: encoding too long
at newInvalidAsn1Error (C:\Users\Smoke\node_modules\asn1\lib\ber\errors.js:7:13)
at Reader.readLength (C:\Users\Smoke\node_modules\asn1\lib\ber\reader.js:102:13)
at Reader.readSequence (C:\Users\Smoke\node_modules\asn1\lib\ber\reader.js:135:16)
at Object.publicImport (C:\Users\Smoke\node_modules\node-rsa\src\formats\pkcs1.js:118:14)
at Object.detectAndImport (C:\Users\Smoke\node_modules\node-rsa\src\formats\formats.js:65:48)
at NodeRSA.module.exports.NodeRSA.importKey (C:\Users\Smoke\node_modules\node-rsa\src\NodeRSA.js:183:22)
at Object.<anonymous> (C:\Users\Smoke\Desktop\sahil.js:10:13)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)

    Process finished with exit code 1

搜索了Internet,但没有得到答案。请帮忙。预先感谢。

0 个答案:

没有答案