<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div><br></div><div>First of all I am a newbie to this list and to cryptography, padding, and C language. Please, bear with me.</div><div><br></div><div>I am trying to encrypt some data on an embedded Linux system using OpenSSL crypto library and decrypt it on a Windows system.</div><div><br></div><div>I am following example at following link for C codes on embedded system: <a href="https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption">https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption</a></div><div>Fortunately, I could encrypt with given code on that embedded linux system using OpenSSL Library version used was: 1.0.0e </div><div>I do not have a change to use another version of the library. I am needed to be provided newer/older library by the device manufacturer to be able to cross compile my C code using their SDK.<br></div><div><br></div><div>My tests on embedded device works in both ways. I can encrypt and decrypt simple string (or below provided example data) on that system.</div><div>My problem is, I need to decrypt on Windows OS what is crypt on the embedded device.</div><div>Windows OS, I am using Delphi (Object Pascal) for my programming needs.</div><div>As I have not enough cryptography knowledge, I am using an open source library from mORMot project. This project supports AES256-CBC, AES256-CFB and several other AES based encryption and decryption, some hashing, etc. I have used that library before and it did work well for my needs. Thing is, I only used mORMot for my encryption and decryption which simply works. Similarly, OpenSSL encryption and decryption works on that embedded Linux system. I failed to make them talk to each other, properly.</div><div><br></div><div>A- I tried to directly decrypt (no padding applied) and I get my plain text plus some additional invisible characters at the end. I am told it maybe a "padding" issue, my problem, during decryption.</div><div>B- I tried PKCS#7 for decryption and it fails (no text being returned. All bytes are zero and of course that returns an empty string.</div><div><br></div><div>Below is encrypt base64 data on embedded linux system.</div><div><font face="monospace, monospace">8XnbAER2Mh4GLQpDrBLA24R0uEm2SkqDqa0U/PZ3KsSCZsKmJ+WKoYqx7dTiLC/uvJivgm2LOJ0mD5U4NQ19SZgYbT1TByMlLL+075EF8LsXotySz2hze2IozKOB8TG4dn2W/nDdM5deO7csBY28onQHOV4wbqzInUeaLVzbvAI=</font><br></div><div><br></div><div>Attached is crypt data saved directly in a file. My tests, base64 decodes to identical bytes as in that file.</div><div><br></div><div>Plain text should be (last character is invisible '\n'):</div><div><font face="monospace, monospace">0000010000012018122721570520181227215705 00017214422c4277d76H  10350514.44    0.01  10350514.43         0.010000</font><br></div><div><br></div><div>For test purposes my key and IV are simple. </div><div>Key: bytes from 0 to 31 (inclusive)</div><div>IV: bytes from 0 to 15 (inclusive)</div><div><br></div><div>C code I used for generating key and IV is something like:<br></div><div><div><div><font face="monospace, monospace"><span style="white-space:pre">   </span>unsigned char key[32];</font></div><div><font face="monospace, monospace"><span style="white-space:pre"> </span>unsigned char iv[16];</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><span style="white-space:pre">     </span>for(i = 0;  i < sizeof(key);  i++)</font></div><div><font face="monospace, monospace"><span style="white-space:pre">                </span>key[i] = i;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><span style="white-space:pre">    </span>for(i = 0;  i < sizeof(iv);  i++)</font></div><div><font face="monospace, monospace"><span style="white-space:pre">         </span>iv[i] = i;<span style="white-space:pre">   </span></font></div></div><div><br></div><div>What I see on Windows after directly decrypting is something as below (I used some embedded picture to be able to show invisible characters at the end)</div><div><div><img src="cid:ii_jq72yqoi1" alt="image.png" style="margin-right: 0px;"><br></div></div><div><br></div><div>My questions are (please keep in mind that I maybe asking non-sense):</div><div>1- Is OpenSSL version 1.0.0e using some kind of proprietary padding?</div><div>I read something in this accepted answer: <a href="https://stackoverflow.com/questions/11783062/how-to-decrypt-file-in-java-encrypted-with-openssl-command-using-aes">https://stackoverflow.com/questions/11783062/how-to-decrypt-file-in-java-encrypted-with-openssl-command-using-aes</a></div><div>I also remember reading PKCS#5 is identical to PKCS#7 in another answer (which failed to work in my case).</div><div><br></div><div>2- What should I do to properly decrypt and receive plain text without additional characters in the end?</div><div><br></div><div>I appreciate any help.</div><div><br></div><div>Thanks & regards,</div><div>Ertan Küçükoğlu</div><div><br></div></div></div></div></div></div></div></div></div></div></div></div>