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 »

Password Encryption & Decryption samples


Posted Date: 05 Oct 2007    Resource Type: Code Snippets    Category: Encryption
Author: Pradeep KintaliMember Level: Gold    
Rating: 1 out of 5Points: 10



Here is 2 simple functions for Password Encryption and Decryption.



using System.Security.Cryptography;
private string EncryptedPassword(string ValueToEncrypt)
{
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, cryptObj.CreateEncryptor(KEY_128,
IV_128), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs);
sw.Write(ValueToEncrypt);
sw.Flush();
cs.FlushFinalBlock();
ms.Flush();
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);

}

private string DecryptedPassword(string ValueToDecrypt)
{
byte [] buf = Convert.FromBase64String(ValueToDecrypt);
MemoryStream ms = new MemoryStream(buf);
CryptoStream cs = new CryptoStream(ms, cryptObj.CreateDecryptor(KEY_128,
IV_128), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
return sr.ReadToEnd();

}





Responses

Author: Shadab Hasn    05 Feb 2008Member Level: Bronze   Points : 0
Hi i an geting error on the following line,

CryptoStream cs = new CryptoStream(ms, cryptObj.CreateEncryptor(KEY_128, IV_128), CryptoStreamMode.Write);

"The name 'cryptObj' does not exist in the current context D:\Cryptography\Default2.aspx.cs"

http://www.dotnetspider.com/code/C-539-Password-Encryption-Decryption-samples.aspx


Pls help me


Author: santhoshkumar    28 Apr 2008Member Level: Gold   Points : 2
Hi please try to explain this ..
CryptoStream cs = new CryptoStream(ms, cryptObj.CreateEncryptor(KEY_128,
IV_128), CryptoStreamMode.Write);

What is the meaning of this line and if "KEY_128,IV_128" it is a key then shalll we use some other key, please mention some other key with explation. please


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

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: How to input and encrypt password in a console application
Previous Resource: Salted-MD5 Encryption
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