It's pretty simple, just call Seek() on the cipher object before you do the encryption or decryption. For example:

CTR_Mode<AES>::Encryption enc;
enc.SetKeyWithIV(key, keysize, iv);
enc.Seek(location);
enc.ProcessData(ciphertext, plaintext, length);

Please note that doing random encrypted writes is not a good idea unless you know what you are doing. If you use the same keystream to encrypt two different messages (for example if you seek to previous location and then encrypt something else) you will allow an attacker to obtain the XOR of those messages. Random reads are safe though.

----- Original Message ----- From: <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, December 02, 2006 3:11 AM
Subject: Random Access mode sample code?


Anyone have any sample code for doing random reads and writes on an AES file with CTR MODE?



Reply via email to