@@ -3561,12 +3561,12 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
35613561
35623562 // Check if this is a PKCS#8 or RSA public key before trying as X.509 and
35633563 // private key.
3564- if (operation == kEncrypt &&
3564+ if (operation == kPublic &&
35653565 strncmp (key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0 ) {
35663566 pkey = PEM_read_bio_PUBKEY (bp, nullptr , nullptr , nullptr );
35673567 if (pkey == nullptr )
35683568 goto exit;
3569- } else if (operation == kEncrypt &&
3569+ } else if (operation == kPublic &&
35703570 strncmp (key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0 ) {
35713571 RSA* rsa = PEM_read_bio_RSAPublicKey (bp, nullptr , nullptr , nullptr );
35723572 if (rsa) {
@@ -3577,7 +3577,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem,
35773577 }
35783578 if (pkey == nullptr )
35793579 goto exit;
3580- } else if (operation == kEncrypt &&
3580+ } else if (operation == kPublic &&
35813581 strncmp (key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0 ) {
35823582 x509 = PEM_read_bio_X509 (bp, nullptr , CryptoPemCallback, nullptr );
35833583 if (x509 == nullptr )
@@ -5038,13 +5038,21 @@ void InitCrypto(Handle<Object> target,
50385038 env->SetMethod (target, " getCiphers" , GetCiphers);
50395039 env->SetMethod (target, " getHashes" , GetHashes);
50405040 env->SetMethod (target, " publicEncrypt" ,
5041- PublicKeyCipher::Cipher<PublicKeyCipher::kEncrypt ,
5041+ PublicKeyCipher::Cipher<PublicKeyCipher::kPublic ,
50425042 EVP_PKEY_encrypt_init,
50435043 EVP_PKEY_encrypt>);
50445044 env->SetMethod (target, " privateDecrypt" ,
5045- PublicKeyCipher::Cipher<PublicKeyCipher::kDecrypt ,
5045+ PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate ,
50465046 EVP_PKEY_decrypt_init,
50475047 EVP_PKEY_decrypt>);
5048+ env->SetMethod (target, " privateEncrypt" ,
5049+ PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate ,
5050+ EVP_PKEY_sign_init,
5051+ EVP_PKEY_sign>);
5052+ env->SetMethod (target, " publicDecrypt" ,
5053+ PublicKeyCipher::Cipher<PublicKeyCipher::kPublic ,
5054+ EVP_PKEY_verify_recover_init,
5055+ EVP_PKEY_verify_recover>);
50485056}
50495057
50505058} // namespace crypto
0 commit comments