Click here to Skip to main content
Licence 
First Posted 23 Jun 2002
Views 75,583
Bookmarked 24 times

Encryption/Decryption with .NET

By | 23 Jun 2002 | Article
Encryption/Decryption with .NET

Encryption and Decryption

The System.Security.Cryptographic namespace within the Microsoft .NET Framework provides a variety of tools to aid in encryption and decryption. The CryptoStream class is used here to demonstrate the encryption and decryption with System.Security.Cryptographic.SymmetricAlgorithm, such as DESCryptoServiceProvider, RC2CryptoServiceProvider, and RijndaelManaged classes.

I have searched the Internet for some samples and all I found were based on the Microsoft sample code in KB Article Q307010, which basically uses input/output files as source and destination. I would like to have the encryption and decryption done in memory without having to specify source and destination files, so that I could use the code on a web server or so.

After I posted the original code, I found some interesting things about .NET System.Security.Cryptographic.SymmetricAlgorithm classes that they are not able to handle characters which are special to Url. (Don't know why). Therefore, I modified the source code to make it work. I have received a lot of emails regarding "Bad Data" exceptions, when some special characters are contained in the data or key. I emailed my updated code back, but haven't updated the code posted here. Looks like I have to update the code here as well.

For any questions, please contact me at: fangfrank@hotmail.com and I would be happy to answer them a.s.a.p.

Revision History

26 Jun 2002 - Initial Revision

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Frank Fang

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralVB Code decrypted strings PinsussAnonymous19:08 29 Oct '02  
GeneralRe: VB Code decrypted strings PinsussAnonymous23:18 24 Jun '03  
GeneralVB Code that Actually Works PinmemberJeromeH13:07 25 Oct '02  
GeneralError PinsussAnonymous5:16 30 Sep '02  
GeneralYou should net set the key and the IV to the same value PinmemberShaunW3:59 1 Jul '02  
You should never set the key and the IV knowingly to the same value - the IV (Initialization vector) is normally transmitted with the encrypted data whereas the key remains secret - also you should use a different IV each time you encrypt the data whereas you would normally reuse the same key - in this manner you could encrypt the same piece of data (plaintext) twice and get different crypt text however because you transmit the IV with the encrypted data (crypttext) then the recipient can still decrypt the message.

Generalreg. kEY PinsussAnonymous1:30 22 Jul '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 24 Jun 2002
Article Copyright 2002 by Frank Fang
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid