It's quick and dirty, but functional example of using "libgcrypt" (GPG/OpenPGP's encryption library) to do basic file encryption.
NOTE: None of the distributions come with a compiled executable.
I don't feel like learning how cygwin's copyrights work
The hell with the rest of the documentation, I have some CRASS that needs to be played at high volume. I'll show you how it works latter.
The 'CipherClass' constructor initilizes the class with the algorithm 'CipherAlgorithmParameter' in the mode 'CipherModeParameter' with a key size of 'KeySizeParameter' bytes and an IV size of 'IV_SizeParameter'. 'CipherAlgorithmParameter' is any of the ciphers in the gcrypt library (see gcrypt documentation for more information). Same goes for 'CipherModeParameter'. Both key and IV sizes are specified in bytes.
In this example, the CipherClass 'Cipher' is initilized
using the algorithm AES with a 256-bit key size, running in CFB (Cipher
Feed Back) mode. The key size is 256 bits and the IV size is 128
IV creation produces random data for the initilizing
vector and places this in 'IV'. There are two methods in which this
function can be called. 'CreateIV' can allocate memory for the IV
data, or already allocated memory can be used.
Initilize the cipher using the key 'Key' of 'KeySize' length and the initlizing vector (IV) 'IV'. This is required before any calls for encrypting or decrypting.
The exception 'GeneralError' is thrown if for:
Encrypt a buffer of 8-bit data. There are two methods by which this function can be called: Encrypting data to a new location, done by specifiying both an output buffer and an input buffer. This method will not modify anything in the input buffer. The second method will place the cipher text into the plain text buffer, with no need for a seprate output buffer.
The exception 'GeneralError' is thrown if there are any problems trying to encrypt.
Decrypt a buffer of 8-bit data. There are two methods by which this function can be called: Decrypting data to a new location, done by specifiying both an output buffer and an input buffer. This method will not modify anything in the input buffer. The second method will place the plain text into the cipher text buffer, with no need for a seprate output buffer.
The exception 'GeneralError' is thrown if there are any problems trying to decrypt.
This function could be called when the cipher is no longer needed. It will cleanup internal storage, such as the cipher state.
Hash class constructor. 'HashAlgorithmParameter' is any of the digest algorithms in the gcrypt library (see gcrypt documentation for more information).
Start a new hash session. This should be called before each hash generated.
Add data into hash.
Clear hash state. This is recomended after the hash has completed it's operation. This function is also called by the destructor.
Returns a pointer to the resulting hash. This will finilize the hash and no further hashing will be posibal after this until the hash is reinitilized.
Destructor. Called 'Flush' and that's about it.
Key expantion constructor. 'HashAlgorithmParameter' is a message digest algrorithm (see gcrypt documentation for more information). 'SaltLengthParameter' is the length (in bytes) of "salt" value to add to the begining of the key. 'KeySizeParameter' is the desired length of the key (in bytes). If the digest algorithm generates more then this, the key will be truncated.
Expand 'Passphrase' into a strong crypto key. This is done by adding the salt value to the begining of the passphrase and running this through the selected digest algorithm. The result will be placed in 'Key'. Note that memory for 'Key' will be allocated.
This function is simmilar to 'ExpandKey', except it will generate a random salt value. This should be used to create encryption keys, where 'ExpandKey' is used to expand keys durring decryption