C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Encryption »

Encryption of string in C#


Posted Date: 10 Sep 2008    Resource Type: Code Snippets    Category: Encryption
Author: Shivashankar ChincholiMember Level: Gold    
Rating: 1 out of 5Points: 10



//This class is for encrypt the value
//call this method with two parameters text and key "01AB=$6Q"



class EncryptdecryptClass
{
public static string Encrypt(string text, string key)
{

byte[] encodedkey;
byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] bytes;

encodedkey = Encoding.UTF8.GetBytes(key);
DESCryptoServiceProvider csp = new DESCryptoServiceProvider();

bytes = Encoding.UTF8.GetBytes(text);
MemoryStream ms = new MemoryStream();

try
{
CryptoStream cs = new CryptoStream(ms, csp.CreateEncryptor(encodedkey, iv), CryptoStreamMode.Write);

cs.Write(bytes, 0, bytes.Length);
cs.FlushFinalBlock();

}
catch (Exception ex)
{
Logger.LogInfo(ex);
}

return Convert.ToBase64String(ms.ToArray());

}

}



Responses

Author: Amit Srivastava    15 Apr 2009Member Level: Bronze   Points : 2
Thanks for the short snippet for encryption through C#.
Although the overall code looks fine, but it would have been very comfortable on the part of any reader who has come to this site for knowledge gain, if some discussion about classes used, and the methods which are called have been done. Also the namespaces should have been mentioned. Atleast i would have gained much from this. Still, the code is short and helpful.


Author: D.Jeya kumar(JK)    20 Apr 2009Member Level: Diamond   Points : 1
Hi,


Please post with some description about the Code. so that it will be helpful to others who is new to .net.

Regards
JK


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
String  .  Encryption  .  ENCRYPTING WITH C#  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Decryption of string in C#
Previous Resource: ViewState Compression in web page
Return to Discussion Resource Index
Post New Resource
Category: Encryption


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use