Encrypt and decrypt files using c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anilza Popat

    #1

    Encrypt and decrypt files using c#

    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
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Encrypt and decrypt files using c#

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Anilza Popat" <anonymous@disc ussions.microso ft.com> wrote in message
    news:0a2e01c39d 4b$be81c6f0$a50 1280a@phx.gbl.. .[color=blue]
    > 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[/color]


    Comment

    • Bret Mulvey [MS]

      #3
      Re: Encrypt and decrypt files using c#

      "Anilza Popat" <anonymous@disc ussions.microso ft.com> wrote in message
      news:0a2e01c39d 4b$be81c6f0$a50 1280a@phx.gbl.. .[color=blue]
      > 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[/color]

      In the System.Security .Cryptography namespace the PasswordDeriveB ytes 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.


      73106935a4 has some interesting samples.



      Comment

      Working...