vb net code snippets for storing password

The solution for “vb net code snippets for storing password” can be found here. The following code will assist you in solving the problem.

/// 

/// Encrypts a given password and returns the encrypted data
/// as a base64 string.
///

/// An unencrypted string that needs
/// to be secured. /// A base64 encoded string that represents the encrypted
/// binary data.
///

/// This solution is not really secure as we are
/// keeping strings in memory. If runtime protection is essential,
/// should be used.

/// If /// 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 or
/// extension methods. /// The decrypted string.
/// Keep in mind that the decrypted string remains in memory
/// and makes your application vulnerable per se. If runtime protection
/// is essential, should be used.

/// If /// 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);
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in