Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
crypto: allow password protected private keys with publicEncrypt#626
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -831,6 +831,28 @@ assert.equal(bad_dh.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); | ||
| }, encryptedBuffer); | ||
| assert.equal(input, decryptedBufferWithPassword.toString()); | ||
| encryptedBuffer = crypto.publicEncrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: 'password' | ||
| }, bufferToEncrypt); | ||
| decryptedBufferWithPassword = crypto.privateDecrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: 'password' | ||
| }, encryptedBuffer); | ||
| assert.equal(input, decryptedBufferWithPassword.toString()); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test that tests decryption with a bad password? What if password is a buffer, an array, etc.? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup can do | ||
| encryptedBuffer = crypto.privateEncrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: new Buffer('password') | ||
| }, bufferToEncrypt); | ||
| decryptedBufferWithPassword = crypto.publicDecrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: new Buffer('password') | ||
| }, encryptedBuffer); | ||
| assert.equal(input, decryptedBufferWithPassword.toString()); | ||
| encryptedBuffer = crypto.publicEncrypt(certPem, bufferToEncrypt); | ||
| decryptedBuffer = crypto.privateDecrypt(keyPem, encryptedBuffer); | ||
| @@ -850,6 +872,25 @@ assert.equal(bad_dh.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); | ||
| crypto.privateDecrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: 'wrong' | ||
| }, bufferToEncrypt); | ||
| }); | ||
| assert.throws(function() { | ||
| crypto.publicEncrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: 'wrong' | ||
| }, encryptedBuffer); | ||
| }); | ||
| assert.throws(function() { | ||
| encryptedBuffer = crypto.privateEncrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: new Buffer('password') | ||
| }, bufferToEncrypt); | ||
| crypto.publicDecrypt({ | ||
| key: rsaKeyPemEncrypted, | ||
| passphrase: [].concat.apply([], new Buffer('password')) | ||
| }, encryptedBuffer); | ||
| }); | ||
| })(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rename makes the diff noisier than it needs to be.