Updated on Kisan Patel
This post will explain you how to ecrypt passwords or other sensitive data in C#.
Crypto
class provides methods to generate hash values and encrypt passwords or other sensitive data. Crypto class defined in System.Web.Helpers
namespace.
You use Crypto.HashPassword
method to generate a hash value as shown in below code:
string hashedPassword = Crypto.HashPassword(password)
Now, you can use Crypto.VerifyHashedPassword method to determines whether the specified hashedPassword and password are a cryptographic match.
bool success = Crypto.VerifyHashedPassword(string hashedPassword, string password);
Here, Crypto.VerifyHashedPassword
returns true if the hash value is a cryptographic match for the password; otherwise return false.