相关疑难解决方法(0)

我有错误的哈希值?C#密码学

我的文本文件说快速的棕色狐狸跳过懒狗,但是当我尝试从这个文件中获取哈希值时,md5和sha1都与wikipedias结果不同.我有3个问题.1)我在代码中做错了什么?2)我怎样才能更好地使用这段代码?(我需要初始化)3)我如何加盐?

    {
        const int bufSize = 1024 * 8;
        int read;
        byte[] buf = new byte[bufSize];
        string fn = @"b.txt";
        byte[] result1 = new byte[0];
        byte[] result2 = new byte[0];
        SHA1 sha = new SHA1CryptoServiceProvider();
        MD5  md5 = new MD5CryptoServiceProvider();
        sha.Initialize();
        md5.Initialize();
        FileStream fin = File.OpenRead(fn);
        while ((read = fin.Read(buf, 0, buf.Length)) != 0)
        {
            result1 = sha.ComputeHash(buf);
            result2 = md5.ComputeHash(buf);
        }
        fin.Close();
        MessageBox.Show(myFunc(result1));
        MessageBox.Show(myFunc(result2));
    }
Run Code Online (Sandbox Code Playgroud)

c# hash cryptography

1
推荐指数
1
解决办法
3750
查看次数

标签 统计

c# ×1

cryptography ×1

hash ×1