create md5 hash (salt+value)

10.2k Views Asked by At

How could I create the following PHP code in C# ?

Php code:

<?php
    $salt = "salt";
    $value = "hello";
    $password_hashed = md5($salt.$value);
?>

I would appreciate any kind of help. Been testing the following:

https://stackoverflow.com/a/1300927/7312781

But it would only return a wrong string.

        var salt = System.Text.Encoding.UTF8.GetBytes("salt");
        var value = System.Text.Encoding.UTF8.GetBytes("hello");

        var hmacMD5 = new HMACMD5(salt);
        var saltedHash = hmacMD5.ComputeHash(value);

        string hex = BitConverter.ToString(saltedHash);
        MessageBox.Show(hex.Replace("-", ""));

Response: https://gyazo.com/340fe77979c1b0b531d07a8050ce66d1

The response should look like: 06decc8b095724f80103712c235586be

1

There are 1 best solutions below

7
On BEST ANSWER

Hope this will help, it's some modification from given link

class Program {
    static void Main(string[] args) {
        var provider = MD5.Create();
        string salt = "S0m3R@nd0mSalt";
        string password = "SecretPassword";
        byte[] bytes = provider.ComputeHash(Encoding.ASCII.GetBytes(salt + password));
        string computedHash = BitConverter.ToString(bytes);

        Console.WriteLine(computedHash.Replace("-", ""));
    }
}