Password Encryptoin Adn decrypt code to store database and r
password Encryptoin Adn decrypt code to store database and retrive the data from database
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 2, 2014, 1:43 AM EST
Hi krishna angirekula,
Read these links it helps u
http://www.aspdotnet-suresh.com/2010/12/introduction-here-i-will-explain-how-to_28.html
http://www.aspsnippets.com/Articles/Encrypt-and-Decrypt-Username-or-Password-stored-in-database-in-ASPNet-using-C-and-VBNet.aspx
Ashok Yadav184 reputationPosted Dec 2, 2014, 1:44 AM EST
Kunal VaishyaRank #990 · 2K reputationPosted Dec 2, 2014, 7:43 PM EST
Try below Code.
///
/// Encrypts a given password and returns the encrypted data
/// as a base64 string.
///
/// An unencrypted string that needs
/// to be secured.
///
/// binary data.
///
///
/// keeping strings in memory. If runtime protection is essential,
///
///
/// is a null reference.
public string Encrypt(string plainText)
{
if (plainText == null) throw new ArgumentNullException("plainText");
//encrypt data
var data = Encoding.Unicode.GetBytes(plainText);
byte[] encrypted = ProtectedData.Protect(data, null, Scope);
//return as base64 string
return Convert.ToBase64String(encrypted);
}
///
/// Decrypts a given string.
///
/// A base64 encoded string that was created
/// through the
///
///
///
/// and makes your application vulnerable per se. If runtime protection
/// is essential,
///
/// is a null reference.
public string Decrypt(string cipher)
{
if (cipher == null) throw new ArgumentNullException("cipher");
//parse base64 string
byte[] data = Convert.FromBase64String(cipher);
//decrypt data
byte[] decrypted = ProtectedData.Unprotect(data, null, Scope);
return Encoding.Unicode.GetString(decrypted);
}
Reference: http://stackoverflow.com/questions/1678555/password-encryption-decryption-code-in-net
Regards,
Kunal.