This article shows a classical approach to lock a file so that
it doesn't reveal its original content in any software. For
locking a file, a password is required. To view the file again
in its original form, it has to be unlocked with the LOCK
software with the same password which was used to lock the file.
The basic approach used is the symmetric key cryptography. The
file is converted into blocks of 8 bytes and repeatedly XORed
with the similar block of 8 bytes obtained by the password.
Because the encryption used is symmetric key cryptography, the
same process is used for unlocking\decryption. Using the code
Following is the code for main encryption routine. For more
details, look at source code for the comments. int count = (1024
+ keyBytes.Length-1)/keyBytes.Length; for( int i=0 ; i<count ;
i++) Array.Copy( keyBytes , 0 , keybuf , i*keyBytes.Length ,
keyBytes.Length); long lBytesRemaining = stream.Length; long
lPosition = stream.Position ; int nBytesRequested =
(int)System.Math.Min(bufSize , lBytesRemain