CSharpTest.Net
IterationCount Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > IPasswordDerivedBytes Interface : IterationCount Property

Glossary Item Box

Gets or sets the number of iterations for the operation.

Syntax

Visual Basic (Declaration) 
Property IterationCount As Integer
C# 
int IterationCount {get; set;}

Example

Library/Library.Test/TestHashDerivedBytes.cs

C#Copy Code
using (IPasswordDerivedBytes pd = DerivedBytes(TEST_PASSWORD))
{
    pd.IterationCount = 1000;
    byte[] sha1Hash = SHA1.Create().ComputeHash(Password.Encoding.GetBytes(TEST_PASSWORD));
    Rfc2898DeriveBytes pbytes = new Rfc2898DeriveBytes(sha1Hash, DefaultSalt.ToArray(), 1000);
    Assert.AreEqual(pd.GetBytes(20), pbytes.GetBytes(20));
    Assert.AreEqual(pd.GetBytes(35), pbytes.GetBytes(35));

    byte[] test1 = pd.GetBytes(40);
    byte[] test2 = pbytes.GetBytes(40);

    //'RFC' implementation resuses 5 bytes already generated with 'GetBytes(35)', if you call reset these behave the same
    Assert.AreNotEqual(test1, test2);

    Buffer.BlockCopy(test2, 5, test2, 0, 35); //strip the first five bytes
    Array.Resize(ref test1, 35);
    Array.Resize(ref test2, 35);

    Assert.AreEqual(test1, test2); //now they should be the same
}
VB.NETCopy Code
Using pd As IPasswordDerivedBytes = DerivedBytes(TEST_PASSWORD)
    pd.IterationCount = 1000
    Dim sha1Hash As Byte() = SHA1.Create().ComputeHash(Password.Encoding.GetBytes(TEST_PASSWORD))
    Dim pbytes As New Rfc2898DeriveBytes(sha1Hash, DefaultSalt.ToArray(), 1000)
    Assert.AreEqual(pd.GetBytes(20), pbytes.GetBytes(20))
    Assert.AreEqual(pd.GetBytes(35), pbytes.GetBytes(35))

    Dim test1 As Byte() = pd.GetBytes(40)
    Dim test2 As Byte() = pbytes.GetBytes(40)

    ''RFC' implementation resuses 5 bytes already generated with 'GetBytes(35)', if you call reset these behave the same
    Assert.AreNotEqual(test1, test2)

    Buffer.BlockCopy(test2, 5, test2, 0, 35)
    'strip the first five bytes
    Array.Resize(test1, 35)
    Array.Resize(test2, 35)

        'now they should be the same
    Assert.AreEqual(test1, test2)
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