问题
So i navigated to the demos folder of openssl in
/usr/share/doc/libssl-doc/demos/cms
I compiled the test files there
gcc cms_enc.c -o enc -lssl -lcrypto
gcc cms_dec.c -o dec -lssl -lcrypto
Then i started both of them first ./enc then ./dec. Unfortunately the following error occured
140502142240416:error:0200B009:system library:fread:Bad file descriptor:bss_file.c:245:
140502142240416:error:20082002:BIO routines:FILE_READ:system lib:bss_file.c:246:
140502142240416:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:532:
So that means that the CMS implementation in openSSL is broken already? i wanted to use that functionality for my own c++ program but it failed so i wanted to try if even the examples work..
回答1:
I compiled the test files there:
gcc cms_enc.c -o enc -lssl -lcrypto
gcc cms_dec.c -o dec -lssl -lcrypto
...
140502142240416:error:0200B009:system library:fread:Bad file descriptor:bss_file.c:245:
There's a typo in cms_dec.c. Scroll on down to line 50, and swap the out and the NULL. After the swap, it should look like:
/* Decrypt S/MIME message */
if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
goto err;
Then recompile cms_dec.c. After the next run, there should be no error, and decout.txt should be as expected (the same as encr.txt).
来源:https://stackoverflow.com/questions/20937978/cms-encryption-decryption-from-openssl-broken