How can I encrypt and decrypt a file with a 256 key AES in C or C++?
To encrypt using AES-CBC: Instantiate the CBC block cipher class with the AES implementation class. Initialize it with the key and Initialization Vector (IV) for encryption. Process each block of the padded plaintext being encrypted.
Yes, you must provide the same IV for encryption and decryption.
If you are just after AES and do not mind losing flexibility (i.e. you will not replace it with another cryptographic algorithm at some time) then Brian Gladman's AES implementation is a popular choice (both for performance and portability). This is the kind of code which you embed in your own source code.
On the external libraries front, you have plenty of choice, including NSS, OpenSSL, Crypto++... the latter is specifically designed for C++, while the two others are meant for C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With