Administrators PlausiblyDamp Posted November 21, 2008 Administrators Posted November 21, 2008 (edited) The attached sample shows how to use the built in TripleDES provider to encrypt and decrypt a single file. The application was written under VS 2008 but the code itself will happily run against .Net 2 After selecting a file to encrypt enter a password and hit the Generate IV button to generate a random IV for the encryption. When you decrypt the file you need to make sure both the password and IV are the same. If you do not specify these then the system will generate these randomly each time and you will never be able to decrypt an encrypted file! The application itself has no real error handling so make sure you provide a password and an IV otherwise it will just crash. Depending on the actual encryption provider used there are restrictions on the length of the Key and IV - only certain sized byte arrays work (you can use the LegalKeySizes and LegalBlockSizes properties to discover what is valid), a md5 hash returns a byte array that is the correct length to use for the Key so it makes sense to use a hash of a password rather than force restrictions on password sizes. IV could be done the same way however generating a unique IV is easy and as such both methods are used in the sample.EncryptionSample.zip Edited November 21, 2008 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.