Skip to content
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

Open
mishbah opened this issue Jul 2, 2024 · 3 comments
Open
Labels
bug Something isn't working needs triage

Comments

@mishbah
Copy link

mishbah commented Jul 2, 2024

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 well

@mishbah mishbah added bug Something isn't working needs triage labels Jul 2, 2024
@mishbah mishbah changed the title TypeError: Invalid private key pem file when run crypto.privateDecrypt TypeError: Invalid private key pem file when run crypto.privateDecrypt Jul 2, 2024
@wpaulino
Copy link
Contributor

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.

@mishbah
Copy link
Author

mishbah commented Sep 20, 2024

so, what can I do for this?
update bun? @wpaulino

@wpaulino
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants