Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 7 of 7

Thread: Encrypting files with a key. [C#]

  1. #1

    Encrypting files with a key. [C#]

    I'd like to know how to encrypt a text file with a key (e.g. "Alwokdo3443k##@~!es!) so that it can only be unencrypted by providing that key again.
    How can I do this with C#?
    thnx
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  2. #2
    You might try PGP — it’s a great way of encrypting files. Check out the Wikipedia page; it uses public/private keys and is really neat.

    I found a couple of resources regarding using PGP in C#:


    K-Emmys-06: Best Footer; and K-Emmys-06: Most Active Member

  3. #3
    Thanks, if someone could show me some pseudo code that would be great.
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  4. #4
    There’s tons of sample code on the first and third links; about half-way down on the former, and just a few paragraphs down on the latter.


    K-Emmys-06: Best Footer; and K-Emmys-06: Most Active Member

  5. #5
    WTF? PGP!?

    He's has asked for a way of encrypting and decrypting with the same key. That means symmetric encryption, not asymmetric. So anything like PGP or RSA which uses public/private key pairs isn't an option.

    There are a few symmetric ciphers built into the .NET framework, including DES, TripleDES, RC2 and Rijndael.

    I did a quick search and found this which should get you going.

    Good luck.

  6. #6
    Thanks mate. I'm going to see if I can create a class with it all built in so then I can do something like:
    Code:
    FileEncrypter enc = new FileEncrypter();
    enc.EncryptWithKey([streamwriterobject], "password");
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  7. #7
    Rijndael

    go with that. if you are using C#, which i hope you are, there is a c# class for it. You can search google for like "msdn rijndael" and they have examples of it. basically what you will end up doing is something like..

    using (stream s = new filestream(stuff))
    {
    using (StreamWriter sw = new StreamWriter(s)
    {
    //then i believe you need teh Rijndael stream
    //so when you use the stream with rinjdeal, you do a .Write, the Rinjdeal stream will encripte it, then the streamwriter will write it to the file stream, which then when you finish it will flush it to the file.
    }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012