Encrypt and decrypt files using c#

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
B

Bret Mulvey [MS]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top