In OpenSSL 1.0.0d, EVP_PKEY_copy_parameters should work. However, judging by the implementation, public parameters are simply copied:
static int pkey_rsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) { RSA_PKEY_CTX *dctx, *sctx; if (!pkey_rsa_init(dst)) return 0; sctx = src->data; dctx = dst->data; dctx->nbits = sctx->nbits; if (sctx->pub_exp) { dctx->pub_exp = BN_dup(sctx->pub_exp); if (!dctx->pub_exp) return 0; } dctx->pad_mode = sctx->pad_mode; dctx->md = sctx->md; return 1; }
Besides the jweyrich solution, another simple method is first i2d_RSAPrivateKey your RSA key, then d2i_RSAPrivateKey again - there is your copy :)
source share