Symfony2的(FOSUserBundle)SHA512哈希值不匹配,C#SHA512哈希 [英] Symfony2 (FOSUserBundle) SHA512 hash doesn't match C# SHA512 hash

查看:186
本文介绍了Symfony2的(FOSUserBundle)SHA512哈希值不匹配,C#SHA512哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的web应用程序(Symfony2的与FOSUserBundle)作出的帐户和密码lolwut(不带引号)。

注册

这是我security.yml配置的设置:

 安全性:
    EN codeRS:
        FOS \\ UserBundle \\型号\\的UserInterface:
            算法:SHA512
            迭代:1
            EN code_as_bas​​e64:假的

将所得的数据:

 哈希密码:
f57470574dbf29026821519b19539d1c2237e4315d881fa412da978af554740c6b284062a9a4af7d0295d18ebea8ef2e152cf674b283f792fe0b568a93f969cf
盐:
kuc5bixg5u88s4k8ggss4osoksko0g8

现在,因为迭代1集,我假设在C#中SHA512该编码lolwut会给我同样的结果,这是我的逻辑:

 字符串盐=kuc5bixg5u88s4k8ggss4osoksko0g8;
字符串输入=lolwut;
字符串passAndSalt = String.Concat(输入,盐);System.String散列= System.BitConverter.ToString(((System.Security.Cryptography.SHA512)新System.Security.Cryptography.SHA512Managed()).ComputeHash(System.Text.Encoding.ASCII.GetBytes(passAndSalt))).Replace(\"-\", );
返回passAndSalt +< BR>中+散列;

不过,这将返回以下值不匹配FOSUserBundle哈希密码都:

<$p$p><$c$c>82E8CA0408B23DB50EB654EDB50A7926AC73613184054DB82FB6D67CD4186B7A045D265AEDE6E3852CD85B981F15F6615C1C0C6FBF443B1672DF59DE23557BD9

我知道我一定是错的地方做一些事情,但我不能为我的生活弄清楚它是什么,它​​的驾驶我坚果。任何人都可以帮助我在这里,好吗?


解决方案

Symfony的合并密码和盐密码{盐} ,所以这个code将返回相同的散列:

 字符串盐=kuc5bixg5u88s4k8ggss4osoksko0g8;
  字符串输入=lolwut;
  字符串passAndSalt =的String.Format({0} {{{1}}},输入,盐);  System.String散列= System.BitConverter.ToString(((System.Security.Cryptography.SHA512)新System.Security.Cryptography.SHA512Managed()).ComputeHash(System.Text.Encoding.ASCII.GetBytes(passAndSalt))).Replace(\"-\", );
  // Hashed.ToLower()

I made an account on my web app (Symfony2 with FOSUserBundle) and registered with the password "lolwut" (without the quotes).

These are the settings in my security.yml config:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface:
            algorithm:   sha512
            iterations: 1
            encode_as_base64: false

The resulting data:

Hashed password:
f57470574dbf29026821519b19539d1c2237e4315d881fa412da978af554740c6b284062a9a4af7d0295d18ebea8ef2e152cf674b283f792fe0b568a93f969cf
Salt:
kuc5bixg5u88s4k8ggss4osoksko0g8

Now, since the iterations are set on 1, I am assuming that encoding "lolwut" in SHA512 in C# will give me the same result, here's my logic:

string salt = "kuc5bixg5u88s4k8ggss4osoksko0g8";
string input = "lolwut";
string passAndSalt = String.Concat(input, salt);

System.String Hashed = System.BitConverter.ToString(((System.Security.Cryptography.SHA512)new System.Security.Cryptography.SHA512Managed()).ComputeHash(System.Text.Encoding.ASCII.GetBytes(passAndSalt))).Replace("-", "");
return passAndSalt + "<br>" + Hashed;

However, this returns the following value that doesn't match the FOSUserBundle hashed password at all:

82E8CA0408B23DB50EB654EDB50A7926AC73613184054DB82FB6D67CD4186B7A045D265AEDE6E3852CD85B981F15F6615C1C0C6FBF443B1672DF59DE23557BD9

I know I must be doing something wrong somewhere, but I can't for the life of me figure out what it is, and it's driving me nuts. Could anyone help me out here, please?

解决方案

Symfony merges password and salt as password{salt}, so this code will return the same hash:

  string salt = "kuc5bixg5u88s4k8ggss4osoksko0g8";
  string input = "lolwut";
  string passAndSalt = String.Format("{0}{{{1}}}", input, salt);

  System.String Hashed = System.BitConverter.ToString(((System.Security.Cryptography.SHA512)new System.Security.Cryptography.SHA512Managed()).ComputeHash(System.Text.Encoding.ASCII.GetBytes(passAndSalt))).Replace("-", "");
  // Hashed.ToLower()

这篇关于Symfony2的(FOSUserBundle)SHA512哈希值不匹配,C#SHA512哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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