Skip Navigation Links.

MD5 and SHA-1 (to Base-64) with salt

It is possible to add salt to the MD5 algorithm, to mix it up a little. In this case the MD5 value is calculated by:

md5($pass + md5($pass))

The following is an example:

Message: 

 

MD5
SHA-1
SHA-256
SHA-384  
SHA-512  

As a test, MD5 should give:

"Hello": QanUfPUkjafkP9vVWMW4Lg==
and "hello": AmSlyl2cixvk4K9qBx7/WQ==

The code is:

string message;

message = this.tbMessage.Text;

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

MD5 md5 = new MD5CryptoServiceProvider();
SHA1 sha1 = new SHA1CryptoServiceProvider();
SHA256Managed sha256 = new SHA256Managed();
SHA384Managed sha384 = new SHA384Managed();
SHA512Managed sha512 = new SHA512Managed();

//md5($salt.md5($pass))

byte[] messageBytes = encoding.GetBytes(message);

byte[] hashmessage = md5.ComputeHash(messageBytes);


byte[] saltedhash;

hashmessage = md5.ComputeHash(messageBytes);


// aDD salt.
string enc = "";

enc = message+System.Convert.ToBase64String(hashmessage);

// Get the new byte array after adding the salt.

saltedhash = md5.ComputeHash(encoding.GetBytes(enc));

this.tbMD5.Text = Convert.ToBase64String(saltedhash);