Example #1
0
 public static void Pbkdf2_PasswordString_NullPassword()
 {
     AssertExtensions.Throws <ArgumentNullException>("password", () =>
                                                     Rfc2898DeriveBytes.Pbkdf2(
                                                         password: (string)null, s_salt, iterations: 1, HashAlgorithmName.SHA256, s_extractLength)
                                                     );
 }
Example #2
0
 public static void Pbkdf2_PasswordBytes_BogusHash()
 {
     Assert.Throws <CryptographicException>(() =>
                                            Rfc2898DeriveBytes.Pbkdf2(
                                                s_passwordBytes, s_salt, iterations: 1, new HashAlgorithmName("BLAH"), s_extractLength)
                                            );
 }
Example #3
0
 public static void Pbkdf2_PasswordBytes_EmptyHashName()
 {
     AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () =>
                                                 Rfc2898DeriveBytes.Pbkdf2(
                                                     s_passwordBytes, s_salt, iterations: 1, new HashAlgorithmName(""), s_extractLength)
                                                 );
 }
Example #4
0
 public static void Pbkdf2_PasswordBytes_SaltBytes_SaltEmpty()
 {
     byte[] expectedKey = "1E437A1C79D75BE61E91141DAE20".HexToByteArray();
     byte[] key         = Rfc2898DeriveBytes.Pbkdf2(
         new byte[0], salt: new byte[0], iterations: 1, HashAlgorithmName.SHA1, s_extractLength);
     Assert.Equal(expectedKey, key);
 }
Example #5
0
 public static void Pbkdf2_PasswordBytes_SaltBytes_OutputLengthNegative()
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("outputLength", () =>
                                                           Rfc2898DeriveBytes.Pbkdf2(
                                                               s_passwordBytes, s_salt, iterations: 1, HashAlgorithmName.SHA256, -1)
                                                           );
 }
Example #6
0
 public static void Pbkdf2_PasswordBytes_NullSalt()
 {
     AssertExtensions.Throws <ArgumentNullException>("salt", () =>
                                                     Rfc2898DeriveBytes.Pbkdf2(
                                                         s_passwordBytes, salt: (byte[])null, iterations: 1, HashAlgorithmName.SHA256, s_extractLength)
                                                     );
 }
Example #7
0
 public static void Pbkdf2_PasswordString_NullHashName()
 {
     AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () =>
                                                 Rfc2898DeriveBytes.Pbkdf2(
                                                     Password, s_salt, iterations: 1, default(HashAlgorithmName), s_extractLength)
                                                 );
 }
Example #8
0
 public static void Pbkdf2_PasswordString_SaltBytes_IterationsNegative()
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>("iterations", () =>
                                                           Rfc2898DeriveBytes.Pbkdf2(
                                                               Password, s_salt, iterations: -1, HashAlgorithmName.SHA256, s_extractLength)
                                                           );
 }
Example #9
0
        public static void Pbkdf2_Password_Salt_Overlapping_Completely()
        {
            Span <byte> buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            byte[] expected = { 0xBE, 0xA4, 0xEE, 0x0E, 0xC3, 0x98, 0xBF, 0x32 };
            Rfc2898DeriveBytes.Pbkdf2(buffer, buffer, buffer, iterations: 1, HashAlgorithmName.SHA256);
            Assert.Equal(expected, buffer.ToArray());
        }
Example #10
0
 public static void Pbkdf2_PasswordString_InvalidUtf8()
 {
     Assert.Throws <EncoderFallbackException>(() =>
                                              Rfc2898DeriveBytes.Pbkdf2(
                                                  "\uD800", s_salt, iterations: 1, HashAlgorithmName.SHA256, s_extractLength));
 }