I’m developing an application that should encrypt some small (less than 1MB) and large (about 500MB) files.
How can I encrypt files and save encrypted version somewhere on disk effectively (i.e.fast)?
Can I have encryption progress if it took time?
I’m developing an application that should encrypt some small (less than 1MB) and large
Share
Assuming you have an AES key and some output stream, here’s how you could add an encryption decorator to the stream.
This adds the IV to the beginning of the cipher text; when decrypting, you’d need to parse that out to initialize the cipher.
A better solution, longterm, would be to use library that implements the Cryptographic Message Syntax, the basis for S/MIME. This records metadata about the algorithms and keys that can be used for decryption.
I would also recommend an AEAD mode like GCM or CCM if your provider implements it. (The SunJCE does not.) These will verify that the file is decrypted correctly, and has not been corrupted.