CSharpTest.Net
Combine(Hash) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > Hash Class > Combine Method : Combine(Hash) Method

other

Glossary Item Box

If the hash provided is the same size as this hash both hash codes are feed back into the hash algorithm associated with this length of hash to produce the result value. If the hash provided is a different length, it is first hashed with this algorithm before the two values are combined.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Combine( _
   ByVal other As Hash _
) As Hash
C# 
public Hash Combine( 
   Hash other
)

Parameters

other

Example

Library/Library.Test/TestHash.cs

C#Copy Code
Random r = new Random();
byte[] a = new byte[10], b = new byte[10];
r.NextBytes(a);
r.NextBytes(b);

Hash h1 = Hash.SHA256(a);
Hash h2 = Hash.SHA1(b);
Hash h3 = h1.Combine(h2);

Assert.AreEqual(h3.ToString(), Hash.SHA256(
    new CombinedStream(
        new MemoryStream(h1.ToArray()),
        new MemoryStream(Hash.SHA256(h2.ToArray()).ToArray()) //the dissimilar hash is first made the same length
        )).ToString());
VB.NETCopy Code
Dim r As New Random()
Dim a As Byte() = New Byte(10) {}, b As Byte() = New Byte(10) {}
r.NextBytes(a)
r.NextBytes(b)

Dim h1 As Hash = Hash.SHA256(a)
Dim h2 As Hash = Hash.SHA1(b)
Dim h3 As Hash = h1.Combine(h2)

'the dissimilar hash is first made the same length
Assert.AreEqual(h3.ToString(), Hash.SHA256(New CombinedStream(New MemoryStream(h1.ToArray()), New MemoryStream(Hash.SHA256(h2.ToArray()).ToArray()))).ToString())

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys