I want to write a small program in C/C++ which reads a small text file, and encrypts it, using a "internal" key. Then I also want to write another small program which can decrypt the encrypted file using internally the same key.
I looked at openSSL site and googled but found not simple example, has somebody ever tried to do this thing?
Best Solution
Ideally, you could use an existing tool like
ccrypt
, but here goes:Decryption is done by calling
AES_cfb128_encrypt
withAES_DECRYPT
as the last parameter. Note that this code hasn't been given anything more than the most elementary of testing, and that you really should use proper 8-bits random data for ckey and ivec.EDIT: It seems
AES_cfb128_encrypt
accepts data of arbitrary length, so you're not required to encrypt in blocks ofAES_BLOCK_SIZE
(16) bytes.