CSharpTest.Net
SaltedData Constructor(Salt,Stream)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > SaltedData Class > SaltedData Constructor : SaltedData Constructor(Salt,Stream)

salt
data

Glossary Item Box

Combines the salt with the data provided

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal salt As Salt, _
   ByVal data As Stream _
)
C# 
public SaltedData( 
   Salt salt,
   Stream data
)

Parameters

salt
data

Example

Library/Library.Test/TestSalt.cs

C#Copy Code
Salt s = new Salt(Salt.Size.b64);
byte[] testData = new byte[8];
new Random().NextBytes(testData);
byte[] tmp;

using (SaltedData sd = new SaltedData(s, testData))
{
    Assert.AreEqual(16, sd.Length);
    Assert.AreEqual(s, sd.Salt);
    Assert.AreEqual(testData, sd.GetDataBytes());

    tmp = sd.ToArray();
    Assert.AreEqual(16, tmp.Length);
    Assert.AreEqual(tmp, IOStream.ReadAllBytes(sd.ToStream()));
}

using (SaltedData sd = new SaltedData(s, new MemoryStream(testData)))
{
    Assert.AreEqual(s, sd.Salt);
    Assert.AreEqual(testData, sd.GetDataBytes());
    Assert.AreEqual(tmp, sd.ToArray());
}

using (SaltedData sd = new SaltedData(tmp, Salt.Size.b64))
{
    Assert.AreEqual(s, sd.Salt);
    Assert.AreEqual(testData, sd.GetDataBytes());
    Assert.AreEqual(tmp, sd.ToArray());
}
VB.NETCopy Code
Dim s As New Salt(Salt.Size.b64)
Dim testData As Byte() = New Byte(8) {}
New Random().NextBytes(testData)
Dim tmp As Byte()

Using sd As New SaltedData(s, testData)
    Assert.AreEqual(16, sd.Length)
    Assert.AreEqual(s, sd.Salt)
    Assert.AreEqual(testData, sd.GetDataBytes())

    tmp = sd.ToArray()
    Assert.AreEqual(16, tmp.Length)
    Assert.AreEqual(tmp, IOStream.ReadAllBytes(sd.ToStream()))
End Using

Using sd As New SaltedData(s, New MemoryStream(testData))
    Assert.AreEqual(s, sd.Salt)
    Assert.AreEqual(testData, sd.GetDataBytes())
    Assert.AreEqual(tmp, sd.ToArray())
End Using

Using sd As New SaltedData(tmp, Salt.Size.b64)
    Assert.AreEqual(s, sd.Salt)
    Assert.AreEqual(testData, sd.GetDataBytes())
    Assert.AreEqual(tmp, sd.ToArray())
End Using

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys