我在 C# 中有一个哈希算法,简而言之,它是:
string input = "asd";
System.Security.Cryptography.MD5 alg = System.Security.Cryptography.MD5.Create();
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
byte[] hash = alg.ComputeHash(enc.GetBytes(input));
string output = Convert.ToBase64String(hash);
// outputs: eBVpbsvxyW5olLd5RW0zDg==
Console.WriteLine(output);
现在我需要在 php 中复制这种行为,
$input = "asd";
$output = HashSomething($input);
echo $output;
我怎样才能实现它?
我检查了
- md5
- utf8_decode
- utf8_encode
- base64_encode
- base64_decode
- url_decode
但我注意到 php md5 最后没有得到 == ......我错过了什么?
注意:我无法更改 C# 行为,因为它已经实现并且使用此算法将密码保存在我的数据库中。