<div dir="ltr"><br>
<div>
<div class="" itemprop="text">
<p>I'm trying to implement CMS encrypt using ECDH keys. Ref <a href="http://stackoverflow.com/questions/29280688/openssl-cms-with-ecdh-envelopeddata">openssl CMS with ECDH EnvelopedData</a> The command line works flawlessly but my program is giving an error - <br></p><p>Error Encrypting Data<br>140508524291744:error:2E06507D:CMS routines:CMS_add1_recipient_cert:not supported for this key type:cms_env.c:210:</p><p>In code below, recip.pem was created using steps here <a href="http://stackoverflow.com/questions/29280688/openssl-cms-with-ecdh-envelopeddata">openssl CMS with ECDH EnvelopedData</a></p><p>int main (int argc, char **argv)<br>{<br> CMS_ContentInfo *cms1 = NULL;<br> BIO *in = NULL, *out = NULL, *tbio = NULL;<br> X509 *rcert = NULL;<br> int ret = 1;<br> int flags = CMS_STREAM;<br><br> OpenSSL_add_all_algorithms();<br> ERR_load_crypto_strings();<br><br> tbio = BIO_new_file("recip.pem", "r");<br> if (!tbio)<br> goto err;<br><br> rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);<br> if (!rcert)<br> goto err;<br><br> in = BIO_new_file("encr.txt", "r");<br> flags |= CMS_PARTIAL;<br> cms1 = CMS_encrypt(NULL, in, EVP_des_ede3_cbc(), flags);<br><br> CMS_RecipientInfo *ri;<br> ri = CMS_add1_recipient_cert(cms1, rcert, flags);<br> if (!ri)<br> goto err;<br><br> if(!CMS_final(cms1, in, NULL, flags))<br> goto err;<br><br> if (!cms1)<br> goto err;<br><br> out = BIO_new_file("cms1.pem", "w");<br> if(!out)<br> goto err;<br><br> if(!PEM_write_bio_CMS_stream(out, cms1, in, flags))<br> goto err;<br><br> ret = 0;<br><br>err:<br></p><p> ##cleanup<br></p><p>}</p><p>The documentation states ECC keys are not supported yet the commandline
cms app is able to do it without a problem. I stepped through the cms
app but am unable to figure out what I'm doing differently. Also tried
the cms_enc.c from the demos folder but that does not handle ecc keys as
well.</p><p>TIA!<br></p></div></div></div>