如何在C#中创建以下PHP代码?
Php代码:
<?php
$salt = "salt";
$value = "hello";
$password_hashed = md5($salt.$value);
?>
我会感激任何帮助。正在测试以下内容:
https://stackoverflow.com/a/1300927/7312781
但它只会返回一个错误的字符串。
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("-", ""));
回复:https://gyazo.com/340fe77979c1b0b531d07a8050ce66d1
回复应如下:06decc8b095724f80103712c235586be
答案 0 :(得分:4)
希望这会有所帮助,这是对给定链接的一些修改
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("-", ""));
}
}