Encrypt and decrypt files using c#

  • Thread starter Thread starter Anilza Popat
  • Start date Start date
A

Anilza Popat

I would like to know how to encrypt and decrypt files
using c#.
I want a program that asks for password before encrypt or
decrypt the file.

best regards
 
Anilza,

You can use the classes in the System.Security.Cryptography namespace to
encrypt and decrypt files (which are really just byte streams persisted to
disk).

However, if you want to use a password of some sort, you might want to
consider using the MD5 algorithm to hash the password. Basically, you would
hash the password using the MD5 algoritm, creating a hash string of 128
bits. Once you have that, you can then use that as the key for the Rijndael
encryption routine.

Hope this helps.
 
Anilza Popat said:
I would like to know how to encrypt and decrypt files
using c#.
I want a program that asks for password before encrypt or
decrypt the file.

best regards

In the System.Security.Cryptography namespace the PasswordDeriveBytes class
will let you derive a cryptographic key from a password string. You can
then use this key in one of the encryption classes such as Rijndael.

When encrypting/decrypting you can either act on an array of bytes in
memory, or you can use CryptoStream to do stream-based IO but with
cryptography applied.

http://blogs.gotdotnet.com/ivanmed/PermaLink.aspx/01380bfa-caf5-40b9-ace6-59
73106935a4 has some interesting samples.
 
Back
Top