gpt4 book ai didi

javascript - 将 WarpWallet 的哈希算法从 javascript 转换为 C#

转载 作者:数据小太阳 更新时间:2023-10-29 03:57:03 26 4
gpt4 key购买 nike

我正在尝试实现 warpwallet C# 中的代码。我将 cryptsharp 用于其 scrypt 和 PBKDF2 实现。但是,我得到的结果似乎与真实网站不同。

这是我的代码:

static void Main(string[] args)
{
string randomString = "mypassword";
byte[] passwordBytes = Encoding.UTF8.GetBytes(randomString);
byte[] passwordBytesScrypt = new byte[passwordBytes.Length + 1];
Array.Copy(passwordBytes, 0, passwordBytesScrypt, 0, passwordBytes.Length);
passwordBytesScrypt[passwordBytes.Length] = 0x1;

string salt = "salt@gmail.com";
byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
byte[] saltBytesScrypt = new byte[saltBytes.Length + 1];
Array.Copy(saltBytes, 0, saltBytesScrypt, 0, saltBytes.Length);
saltBytesScrypt[saltBytes.Length] = 0x1;

byte[] scryptBytes = CryptSharp.Utility.SCrypt.ComputeDerivedKey(passwordBytesScrypt, saltBytes, 524288, 8, 1, null, 32);

byte[] passwordBytesPBKDF2 = passwordBytesScrypt;
passwordBytesPBKDF2[passwordBytes.Length] = 0x2;

byte[] saltBytesPBKDF2 = saltBytesScrypt;
saltBytesScrypt[saltBytes.Length] = 0x2;

byte[] pbkdf2Bytes = CryptSharp.Utility.Pbkdf2.ComputeDerivedKey(new HMACSHA256(passwordBytesPBKDF2), saltBytes, 65536, 32);
}

根据网站(我修改了代码以登录到控制台),scrypt哈希结果应该是

4dfe98afd8f279e856abdcccce09aa54031fbd7fa39a912bb3caf5ce28648fe6

PBKDF2 哈希结果应该是

847c053e66c093927d1f1258b52455675fe6788e537c2073927fbddddfacc0d3

我的 scrypt 结果是

790BE1F92DDDF297CF7BACAA69218BE2C67680C706B2A214081A559B8E0EF43D

和PBKDF2

CB640D1C8C13B44712EBCF341FA68F22F90D69AA5BC8427CD5ABED37FDFFE4EF

我不明白我做错了什么。 cryptsharp 实现是否不正确?我在某处错过了一步吗?我不太了解javascript,所以这完全有可能。任何帮助将不胜感激。

最佳答案

我发现您的代码有两个问题:

  1. 2^18 不是 524288 而是 262144。
  2. 您注入(inject) 0x1 的方式似乎不起作用,我用不同的方式完成了它并且有效:

        string randomString = "mypassword";

    string salt = "salt@gmail.com";

    //Setup Lists to take the extra byte of the byte array to the end
    var passArrList = new List<byte>();
    var saltArrList = new List<byte>();

    //Get the byte array of incoming passphrase
    byte[] passArr = Encoding.UTF8.GetBytes(randomString);
    //Add the pass byte array to the list
    passArrList.AddRange(passArr);
    //Append the needed 0x1 to the end of the array
    passArrList.Add(1);

    //Get the bytes of the salt
    byte[] saltArr = Encoding.UTF8.GetBytes(salt);
    //Add the salt to the list
    saltArrList.AddRange(saltArr);
    //Append the needed salt to the end
    saltArrList.Add(1);

    byte[] scryptBytes = CryptSharp.Utility.SCrypt.ComputeDerivedKey(passArrList.ToArray(), saltArrList.ToArray(), 262144, 8, 1, null, 32);

    Console.WriteLine(BitConverter.ToString(scryptBytes).Replace("-", ""));

关于javascript - 将 WarpWallet 的哈希算法从 javascript 转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46214568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com