簡體   English   中英

Symfony2(FOSUserBundle)SHA512哈希與C#SHA512哈希不匹配

[英]Symfony2 (FOSUserBundle) SHA512 hash doesn't match C# SHA512 hash

我在我的網絡應用程序(帶有FOSUserBundle的Symfony2)上創建了一個帳戶,並使用密碼“lolwut”注冊(不帶引號)。

這些是我的security.yml配置中的設置:

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

結果數據:

Hashed password:
f57470574dbf29026821519b19539d1c2237e4315d881fa412da978af554740c6b284062a9a4af7d0295d18ebea8ef2e152cf674b283f792fe0b568a93f969cf
Salt:
kuc5bixg5u88s4k8ggss4osoksko0g8

現在,由於迭代設置為1,我假設在C#中SHA512中編碼“lolwut”將給出相同的結果,這是我的邏輯:

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;

但是,這將返回以下與FOSUserBundle哈希密碼完全不匹配的值:

82E8CA0408B23DB50EB654EDB50A7926AC73613184054DB82FB6D67CD4186B7A045D265AEDE6E3852CD85B981F15F6615C1C0C6FBF443B1672DF59DE23557BD9

我知道我必須在某個地方做錯事,但我不能為我的生活找出它是什么,這讓我瘋了。 有人可以幫幫我嗎?

Symfony將password和salt合並為password{salt} ,因此此代碼將返回相同的哈希:

  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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM