创建 md5 哈希(盐+值) [英] create md5 hash (salt+value)

查看:107
本文介绍了创建 md5 哈希(盐+值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 C# 中创建以下 PHP 代码?

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

PHP 代码:

<?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("-", ""));

回复:https://gyazo.com/340fe77979c1b0b531d07a8050ce66d>

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

响应应如下所示:06decc8b095724f80103712c235586be

The response should look like: 06decc8b095724f80103712c235586be

推荐答案

希望这会有所帮助,这是对给定链接的一些修改

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("-", ""));
    }
}

这篇关于创建 md5 哈希(盐+值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆