diff options
author | Calvin Metcalf <cmetcalf@appgeo.com> | 2015-01-27 14:58:22 -0500 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-02-02 23:21:49 +0100 |
commit | 6561274d2377d9fd9c55fa3ce2eb2e53c14d898e (patch) | |
tree | d8e945e564c6aae892f2dcb79df3938b64840248 /test | |
parent | e9eb2ec1c491e82dda27fe07d0eaf14ff569351b (diff) | |
download | node-new-6561274d2377d9fd9c55fa3ce2eb2e53c14d898e.tar.gz |
crypto: support passwords in publicEncrypt
Private keys may be used along with publicEncrypt since the private key
includes the public one. This adds the ability to use encrypted private
keys which previously threw an error. This commit also makes sure the
user exposed functions have names.
PR-URL: https://github.com/iojs/io.js/pull/626
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-crypto.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/parallel/test-crypto.js b/test/parallel/test-crypto.js index 8198a6c9d6..c96299ad0d 100644 --- a/test/parallel/test-crypto.js +++ b/test/parallel/test-crypto.js @@ -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()); + + 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); + }); + + encryptedBuffer = crypto.privateEncrypt({ + key: rsaKeyPemEncrypted, + passphrase: new Buffer('password') + }, bufferToEncrypt); + + assert.throws(function() { + crypto.publicDecrypt({ + key: rsaKeyPemEncrypted, + passphrase: [].concat.apply([], new Buffer('password')) }, encryptedBuffer); }); })(); |