public void TestRfcCompatible()
        {
            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
            }
        }
        public void TestRfcRandom()
        {
            Rfc2898DeriveBytes pd1 = new Rfc2898DeriveBytes(Password.Encoding.GetBytes(TEST_PASSWORD), DefaultSalt.ToArray(), 10);

            using (IPasswordDerivedBytes pd2 = new TestRfc2898(Password.Encoding.GetBytes(TEST_PASSWORD), DefaultSalt.ToArray(), 10))
            {
                Assert.AreEqual(pd1.GetBytes(20), pd2.GetBytes(20));
                Assert.AreEqual(pd1.GetBytes(35), pd2.GetBytes(35));
                Assert.AreEqual(pd1.GetBytes(16), pd2.GetBytes(16));

                Random r = new Random();
                for (int i = 0; i < 1000; i++)
                {
                    int size = r.Next(2, 60);
                    Assert.AreEqual(pd1.GetBytes(size), pd2.GetBytes(size));
                }
            }
        }
 protected override IPasswordDerivedBytes DerivedBytes(string input)
 {
     return(new TestRfc2898(Password.Encoding.GetBytes(input), DefaultSalt.ToArray(), DefaultIterations));
 }