@@ -5203,7 +5203,7 @@ template <PublicKeyCipher::Operation operation,
52035203bool PublicKeyCipher::Cipher (Environment* env,
52045204 const ManagedEVPPKey& pkey,
52055205 int padding,
5206- const char * oaep_hash ,
5206+ const EVP_MD* digest ,
52075207 const unsigned char * data,
52085208 int len,
52095209 AllocatedBuffer* out) {
@@ -5215,9 +5215,8 @@ bool PublicKeyCipher::Cipher(Environment* env,
52155215 if (EVP_PKEY_CTX_set_rsa_padding (ctx.get (), padding) <= 0 )
52165216 return false ;
52175217
5218- if (oaep_hash != nullptr ) {
5219- if (!EVP_PKEY_CTX_md (ctx.get (), EVP_PKEY_OP_TYPE_CRYPT,
5220- EVP_PKEY_CTRL_RSA_OAEP_MD, oaep_hash))
5218+ if (digest != nullptr ) {
5219+ if (!EVP_PKEY_CTX_set_rsa_oaep_md (ctx.get (), digest))
52215220 return false ;
52225221 }
52235222
@@ -5259,6 +5258,12 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
52595258
52605259 const node::Utf8Value oaep_str (env->isolate (), args[offset + 2 ]);
52615260 const char * oaep_hash = args[offset + 2 ]->IsString () ? *oaep_str : nullptr ;
5261+ const EVP_MD* digest = nullptr ;
5262+ if (oaep_hash != nullptr ) {
5263+ digest = EVP_get_digestbyname (oaep_hash);
5264+ if (digest == nullptr )
5265+ return THROW_ERR_OSSL_EVP_INVALID_DIGEST (env);
5266+ }
52625267
52635268 AllocatedBuffer out;
52645269
@@ -5268,7 +5273,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
52685273 env,
52695274 pkey,
52705275 padding,
5271- oaep_hash ,
5276+ digest ,
52725277 buf.data (),
52735278 buf.length (),
52745279 &out);
0 commit comments