Open
Description
I created a helper to get the public and private key. The pems files have been created with new NodeRSA ({b:1024})
:
const fs = require("fs");
const NodeRSA = require("node-rsa");
const getKeys = () => {
const publicPem = fs.readFileSync("./public.pem", "utf8");
const privatePem = fs.readFileSync("./private.pem", "utf8");
const privateKey = new NodeRSA(privatePem);
const publicKey = new NodeRSA(publicPem);
return {
privateKey,
publicKey,
privatePem,
publicPem,
};
};
const RSA = {
getKeys,
};
module.exports = { RSA };
i can encrypt with publicKey.encrypt(data, "base64")
. And, i can decrypt with privateKey.decrypt(encryptedData,'utf8')
.
but...
I can't decrypt if I didn't create any encryption before. Just to give you an idea, I have to do this for the decryption to work:
publicKey.encrypt(""); //bug
const decryptedData= privateKey.decrypt(encryptedRSA, "utf8");
without publicKey.encrypt(""); //bug
the terminal returns next error:
throw Error('Error during decryption (probably incorrect key). Original error: ' + e);
^
Error: Error during decryption (probably incorrect key). Original error: Error: error:25078067:DSO support routines:win32_load:could not load the shared library
at NodeRSA.module.exports.NodeRSA.$$decryptKey (C:\....\project-name\node_modules\node-rsa\src\NodeRSA.js:301:19)
at NodeRSA.module.exports.NodeRSA.decrypt (C:\...\project-name\node_modules\node-rsa\src\NodeRSA.js:249:21)
at Object.decrypt (C:\....\MyHelper.js:20:38)
at Object.<anonymous> (C:\...\index.js:7:37)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
npm v8.6.0
node v16.14.2
node-rsa v1.1.1
Summary
// Works
const encryptedData = publicKey.encrypt(data, "base64");
const decryptedData = privateKey.decrypt(encryptedData , "utf8");
// Not works
// const encryptedData = publicKey.encrypt(data, "base64");
const decryptedData = privateKey.decrypt("your base64 encryption", "utf8");
// Works
publicKey.encrypt("");
const decryptedData = privateKey.decrypt("your base64 encryption", "utf8");
reproduce error:
- Encrypt anything.
- Copy the encrypted result.
- remove or comment out the lines of code that do the encryption
- try decrypt. (not works)
Metadata
Metadata
Assignees
Labels
No labels