コード例 #1
0
        public void Generate_returns_correct_result()
        {
            foreach (var i in TestData)
            {
                var expected = i.Expected.Decode64();

                Assert.That(Pbkdf2.Generate(i.Password,
                                            i.Salt,
                                            i.IterationCount,
                                            expected.Length),
                            Is.EqualTo(expected));

                Assert.That(Pbkdf2.Generate(i.Password.ToBytes(),
                                            i.Salt,
                                            i.IterationCount,
                                            expected.Length),
                            Is.EqualTo(expected));

                Assert.That(Pbkdf2.Generate(i.Password,
                                            i.Salt.ToBytes(),
                                            i.IterationCount,
                                            expected.Length),
                            Is.EqualTo(expected));

                Assert.That(Pbkdf2.Generate(i.Password.ToBytes(),
                                            i.Salt.ToBytes(),
                                            i.IterationCount,
                                            expected.Length),
                            Is.EqualTo(expected));
            }
        }
コード例 #2
0
        public void GenerateSha256_returns_correct_result()
        {
            foreach (var i in _testDataSha256)
            {
                var expected = i.Expected.DecodeHex();

                Assert.AreEqual(expected,
                                Pbkdf2.GenerateSha256(i.Password, i.Salt, i.IterationCount, expected.Length));
                Assert.AreEqual(expected,
                                Pbkdf2.Generate <HMACSHA256>(i.Password, i.Salt, i.IterationCount, expected.Length));
            }
        }
コード例 #3
0
 public void Generate_throws_on_negative_byteCount()
 {
     Pbkdf2.Generate(_testData[0].Password, _testData[0].Salt, _testData[0].IterationCount, -1);
 }
コード例 #4
0
 public void Generate_throws_on_negative_iterationCount()
 {
     Pbkdf2.Generate(_testData[0].Password, _testData[0].Salt, -1, _testData[0].Expected.Decode64().Length);
 }
コード例 #5
0
 private void Generate(int iterationCount, int byteCount)
 {
     Pbkdf2.Generate <NoopHmac>("password", "salt", iterationCount, byteCount);
 }
コード例 #6
0
 public void Generate_throws_on_negative_iterationCount()
 {
     Assert.That(() => Pbkdf2.Generate("password", "salt", -1, 32),
                 Throws.InstanceOf <ArgumentOutOfRangeException>()
                 .And.Message.StartsWith("Iteration count should be positive"));
 }
コード例 #7
0
 public void Generate_throws_on_negative_byteCount()
 {
     Assert.That(() => Pbkdf2.Generate("password", "salt", 1, -1),
                 Throws.InstanceOf <ArgumentOutOfRangeException>()
                 .And.Message.StartsWith("Byte count should be nonnegative"));
 }