Encrypt/Decrypt

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
I need a way to encrypt and then decrypt a stream of bytes.

There are many techniques that I've found on how to encrypt a file, but decrypting the information so that it can be used again seems to be a secret.

Has anyone run across something that shows how to encrypt then decrypt a file?
 
I hate to keep bothering you about this, but I've run into a related question:

Given a file (could be an image, a zipped archive, a text file, PDF, etc), how could my application tell if the file has already been encrypted with my technique?

I want to retain whatever extensions are already on the original file formats whenever they are encrypted and replace the original file with the encrypted version - unless they are already encrypted! If they are already encrypted, I want to decrypt them. I just don't know how to test for a file or a stream already being encrypted.
 
Probably the easiest way is when writing the encrypted version make the file contents start with a particular byte sequence, when opening the file check for this sequence - if it exists then it needs to be decrypted if it doesn't assume it is already decrypted.
 
Back
Top