C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Password Encryption And Decryption


Posted Date: 06 Sep 2008    Resource Type: Code Snippets    Category: Encryption

Posted By: vipul       Member Level: Diamond
Rating:     Points: 10



Here is cod for encryption and Decryption of the password.
For Encryption

Private Shared KEY_64() As Byte = {42, 16, 93, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 103, 246, 79, 36, 99, 167, 3}

public static string Encryption(string value)
{
if (value != "")
{
DESCryptoServiceProvider CryptoProvidor = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, CryptoProvidor.CreateEncryptor(Key_64, Iv_64), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs);
sw.Write(value);
sw.Flush();
cs.FlushFinalBlock();
ms.Flush();
return Convert.ToBase64String(ms.GetBuffer(), 0, Convert.ToInt32(ms.Length));
}
return string.Empty;
}


For Decryption

public static string Descryption(string value)
{
if (value != "")
{
DESCryptoServiceProvider CryptoProvidor = new DESCryptoServiceProvider();
Byte[] buf = Convert.FromBase64String(value);
MemoryStream ms = new MemoryStream(buf);
CryptoStream cs = new CryptoStream(ms, CryptoProvidor.CreateDecryptor(Key_64, Iv_64), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
return sr.ReadToEnd();
}
return string.Empty;
}


How to Use
----------
-> When User enter their new password then you pass the string to "Encryption" method they take one argument as as string this way

string strencryptpwd = Encryption(yourpassword);


this is return encrypt string store this code in the database.

-> When you retire that password from the database then pass that encrypt string to "Descryption" method they accept encrypt string and return orignal value. This way

string strencryptpwd = Descryption(yourencryptstring);





Responses

Author: VinC    16 Sep 2008Member Level: Silver   Points : 0
what is Key_64 and Iv_64 ? and where u r filling them ?


Author: vipul    16 Sep 2008Member Level: Diamond   Points : 0
Sorry,
i can't add in the code now check.


Author: Devbrat Ghosh    07 Oct 2008Member Level: Bronze   Points : 2
Dear vipul,
Please update this article. Array declaration is done in Vb.net syntax as
Private Shared KEY_64() As Byte = {42, 16, 93, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 103, 246, 79, 36, 99, 167, 3}
where it must be as
public static Byte[] Key_64= { 42,16,93,156,78,4,218,32 };
public static Byte[] Iv_64= { 55,103,246,79,36,99,167,3 };

Since in method Key_64 and Iv_64 is used ; so I changed it in declaration portion.
Thanks for your code. Its working fine.
Regards
Dev


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Password Encryption And Decryption  .  Encryption  .  Decryption  .  

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: Bit Wise Encryption & decryption
Previous Resource: Decryption of string in C#
Return to Discussion Resource Index
Post New Resource
Category: Encryption


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use