-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Invalid private key pem file
when run crypto.privateDecrypt
#12287
Comments
TypeError: Invalid private key pem file
when run crypto.privateDecrypt
This can only happen when the passphrase is empty, which seems to be an issue with BoringSSL upstream. I reported it at https://issues.chromium.org/issues/362788352. |
so, what can I do for this? |
The fix has been included in BoringSSL upstream. You'll have to wait for Bun's BoringSSL fork to include the fix and then wait for a new Bun release. Alternatively, don't use an empty passphrase and your code snippet should work. |
What version of Bun is running?
1.1.17
What platform is your computer?
Linux 5.15.0-107-generic x86_64 x86_64
What steps can reproduce the bug?
I follow tutorial from this site https://www.geeksforgeeks.org/node-js-crypto-privatedecrypt-method/ at "Example 2"
and when I try to run
bun src/index.js
show up the error:
TypeError: Invalid private key pem file
What is the expected behavior?
Plaintext: Geeks!
Encrypted Text:
ACks6H7InpaeGdI4w9MObyD73YB7N1V0nVsG5Jl10SNeH3no6gfgjeD4ZFsSFhCXzFkognMGbRNsg0BReVOHxRs7eQ==
Decrypted Text: Geeks!
What do you see instead?
Plaintext: Geeks!
Encrypted Text: EQfTaY5gnk8wUiDNhsuFO9yJvZjF4qjdeCxg aWUqrKoDS7l6d5nTfnLaZlHN1mMMpGdcYTWSIjZTakIWtREhw==
43 | // Creating a function to decrypt string
44 | function decryptString(ciphertext, privateKeyFile) {
45 | const privateKey = fs.readFileSync(privateKeyFile, "utf8");
46 |
47 | // privateDecrypt() method with its parameters
48 | const decrypted = crypto.privateDecrypt(
^
TypeError: Invalid private key pem file
at node:crypto:66:32
at node:crypto:16:25
at node:crypto:9227:39
at decryptString (/home/my_name/my_project/src/test.js:48:28)
Additional information
if using
pnpm
working wellThe text was updated successfully, but these errors were encountered: