如何将带有两个更新语句的 Java MessageDigest 转换为 C#

How to convert Java MessageDigest with two update statements to C#

如何将此 Java 代码转换为 C#?

    byte[] a = ...some byte array...;
    byte[] b = ...some byte array...;

    MessageDigest m_Hash = MessageDigest.getInstance("SHA-1");
    m_Hash.update(a);
    m_Hash.update(b);
    byte[] ub = m_Hash.digest();

到目前为止我有:

        var hash = HashAlgorithm.Create("SHA-1");
        hash.ComputeHash(a);
        hash.ComputeHash(b);

但我不认为这是朝着正确的方向发展,因为 ComputeHash 实际上 returns 一个字节[]。

所以...看起来更新只是附加字节数组...我写了一个函数来执行此操作,它看起来像这样:

    var hash = HashAlgorithm.Create("SHA-1");
    byte[] ub = hash.ComputeHash(AppendArrays(a, b));

    public byte[] AppendArrays(byte[] b1, params byte[][] others)
    {
        int n = b1.Length;
        foreach (var other in others)
            n += other.Length;

        var result = new byte[n];

        n = 0;
        Array.Copy(b1, 0, result, n, b1.Length);
        n += b1.Length;
        foreach (var other in others)
        {
            Array.Copy(other, 0, result, n, other.Length);
            n += other.Length;
        }

        return result;
    }