I want to convert a Secure Password in secure hashcode. best method?
like: SHA1,MD5 and any combination ?
string str ="Krishna";
Output:"!#$!$ASDFAS@#$%@";
There are different ways to create a random piece of data that can be used for salting. The most common ones are:
Guid typeRNGCryptoServiceProvider classTo create a new random GUID, we invoke the NewGuid method on the Guid type. Once generated, we simply append the salt to the string to be encrypted.
string saltAsString = Guid.NewGuid().ToString();
For creating a random string of digits by using the RNGCryptoServiceProvider class, we first initialize a provider and a byte array, and then invoke the GetBytes method on our provider instance.
byte[] saltInBytes = new byte[8];
RNGCryptoServiceProvider saltGenerator = new RNGCryptoServiceProvider();
saltGenerator.GetBytes(saltInBytes);
string saltAsString = Convert.ToBase64String(saltInBytes);
The following code is a modified version of the previous snippet to demonstrate salting.
public void HashText()
{
string textToHash = "password";
string saltAsString = Guid.NewGuid().ToString();
byte[] byteRepresentation
= UnicodeEncoding.UTF8.GetBytes(textToHash + saltAsString);
byte[] hashedTextInBytes = null;
MD5CryptoServiceProvider myMD5 = new MD5CryptoServiceProvider();
hashedTextInBytes = myMD5.ComputeHash(byteRepresentation);
string hashedText = Convert.ToBase64String(hashedTextInBytes);
// will display X03MO1qnZdYdgyfeuILPmQ==
MessageBox.Show(hashedText);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With