duanmei1885 2018-06-22 07:36
浏览 79

在c#中使用Rfc2898DeriveBytes在go中生成不同的密钥,并在pbkdf2中生成不同的密钥

Here is the C# sample code to verify the hash password.

Salt size is 8 which generates random bytes, 10000 time Iteration and Hash size is 20.

    public static bool VerifyHashedString(string inputString, string hashedString)
    {
        try
        {
            byte[] hashBytes = Convert.FromBase64String(hashedString);
            var salt = new byte[8];
            Array.Copy(hashBytes, 0, salt, 0, 8);

            var pbkdf2 = new Rfc2898DeriveBytes(inputString, salt, 10000);
            byte[] hash = pbkdf2.GetBytes(20);

            for (var i = 0; i < 20; i++)
            {
                if (hashBytes[i + 8] != hash[i])
                {
                    return false;
                }
            }
            return true;
        }
        catch
        {
            return false;
        }
    }

And I am using following code to verify in golang - please find the link https://github.com/anaskhan96/go-password-encoder but I am not able to match hash text

what could be the reason ?

Following are the observation Hash password length varies.

in C# KwLur0TzENvIVUmvTg0gqPUh+Jkndlu2bH7L8g==

in Golang KETc4Dp1kZzPC6pdePc5OQyDXLA=

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 STM32驱动继电器