EVP_PKEY_decrypt(3) OpenSSL EVP_PKEY_decrypt(3) NNAAMMEE EVP_PKEY_decrypt_init, EVP_PKEY_decrypt - decrypt using a public key algorithm SSYYNNOOPPSSIISS #include int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen); DDEESSCCRRIIPPTTIIOONN The _E_V_P___P_K_E_Y___d_e_c_r_y_p_t___i_n_i_t_(_) function initializes a public key algorithm context using key ppkkeeyy for a decryption operation. The _E_V_P___P_K_E_Y___d_e_c_r_y_p_t_(_) function performs a public key decryption opera- tion using ccttxx. The data to be decrypted is specified using the iinn and iinnlleenn parameters. If oouutt is NNUULLLL then the maximum size of the output buffer is written to the oouuttlleenn parameter. If oouutt is not NNUULLLL then before the call the oouuttlleenn parameter should contain the length of the oouutt buffer, if the call is successful the decrypted data is written to oouutt and the amount of data written to oouuttlleenn. NNOOTTEESS After the call to _E_V_P___P_K_E_Y___d_e_c_r_y_p_t___i_n_i_t_(_) algorithm specific control operations can be performed to set any appropriate parameters for the operation. The function _E_V_P___P_K_E_Y___d_e_c_r_y_p_t_(_) can be called more than once on the same context if several operations are performed using the same parame- ters. RREETTUURRNN VVAALLUUEESS _E_V_P___P_K_E_Y___d_e_c_r_y_p_t___i_n_i_t_(_) and _E_V_P___P_K_E_Y___d_e_c_r_y_p_t_(_) return 1 for success and 0 or a negative value for failure. In particular a return value of -2 indicates the operation is not supported by the public key algorithm. EEXXAAMMPPLLEE Decrypt data using OAEP (for RSA keys): #include #include EVP_PKEY_CTX *ctx; unsigned char *out, *in; size_t outlen, inlen; EVP_PKEY *key; /* NB: assumes key in, inlen are already set up * and that key is an RSA private key */ ctx = EVP_PKEY_CTX_new(key); if (!ctx) /* Error occurred */ if (EVP_PKEY_decrypt_init(ctx) <= 0) /* Error */ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_OAEP_PADDING) <= 0) /* Error */ /* Determine buffer length */ if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0) /* Error */ out = OPENSSL_malloc(outlen); if (!out) /* malloc failure */ if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0) /* Error */ /* Decrypted data is outlen bytes written to buffer out */ SSEEEE AALLSSOO _E_V_P___P_K_E_Y___C_T_X___n_e_w(3), _E_V_P___P_K_E_Y___e_n_c_r_y_p_t(3), _E_V_P___P_K_E_Y___s_i_g_n(3), _E_V_P___P_K_E_Y___v_e_r_i_f_y(3), _E_V_P___P_K_E_Y___v_e_r_i_f_y___r_e_c_o_v_e_r(3), _E_V_P___P_K_E_Y___d_e_r_i_v_e(3) HHIISSTTOORRYY These functions were first added to OpenSSL 1.0.0. 1.0.2u 2019-12-20 EVP_PKEY_decrypt(3)