我正在尝试在 C#中实现warpwallet代码。我将 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,所以这是完全可能的。任何帮助,将不胜感激。