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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal VaishyaPosted Dec 3, 2014, 12:43 AM
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.
Ashok YadavPosted Dec 2, 2014, 6:44 AM
Manish Kumar ChoudharyPosted Dec 2, 2014, 6:43 AM
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