开发者

Problem with encryption & decryption of binary files

开发者 https://www.devze.com 2023-01-12 14:59 出处:网络
How can I encrypt & decrypt binary files in C using OpenSSL? I have a test program that encrypts and then decrypts the input it\'s given.

How can I encrypt & decrypt binary files in C using OpenSSL?

I have a test program that encrypts and then decrypts the input it's given.

I executed my test program for text files, and the output is the same as the input, but when I e开发者_运维问答xecute my test program on a binary file the output is not the same as the input.


Just guessing: you are using Windows and missed O_BINARY flag in file operations?


Chances are you are using string functions like strlen() on the buffers you're reading. The OpenSSL functions work fine for binary files.


Without seeing your code we can only guess. But my first guess would be that your encryption or decryption routine is barfing on a \0 character or two within the binary file. The data must be treated as bytes not as character strings. (Same as the StrLen() problem mentioned elsewhere on this page.)

I'm not a C programmer(!) but the way I managed to get the encryption routines working within Delphi/Pascal was by downloading the OpenSSL source (in C) and stepping through the code for the openssl.exe application. Using the EVP_* functions became a whole lot easier once you work out how they do it themselves.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号