protected override void Arrange()
            {
                var packedHash = new PackedHash
                {
                    Format        = 1,
                    HashAlgorithm = 123,
                    HashBytes     = new byte[]
                    {
                        111,
                        222,
                        200
                    },
                    Iterations = 321,
                    Salt       = new byte[]
                    {
                        100,
                        200,
                        201
                    }
                };

                var secureHasher = A.Fake <ISecureHasher>();

                A.CallTo(() => secureHasher.ComputeHash("MySecret", 123, 321, 3))
                .Returns(packedHash);

                var packedHashConverter = A.Fake <IPackedHashConverter>();

                A.CallTo(() => packedHashConverter.GetBase64String(packedHash))
                .Returns("MyHashedSecret");

                _securePackedHashProvider = new SecurePackedHashProvider(packedHashConverter, secureHasher);
            }
            protected override void Act()

            {
                var packedHashConverter = new PackedHashConverter();

                _actualPackedHash = packedHashConverter.GetPackedHash(_base64String);
            }
예제 #3
0
            protected override void Arrange()
            {
                var packedHash = new PackedHash
                {
                    Format = 1, HashAlgorithm = 123, HashBytes = new byte[]
                    {
                        111, 222, 200
                    },
                    Iterations = 321, Salt = new byte[]
                    {
                        100, 200, 201
                    }
                };

                var packedHashConverter = mocks.Stub <IPackedHashConverter>();

                packedHashConverter.Stub(phc => phc.GetPackedHash("MyHashedSecret"))
                .Return(packedHash);

                var secureHasher = mocks.Stub <ISecureHasher>();

                secureHasher.Stub(
                    sh => sh.ComputeHash(
                        "MySecret",
                        123,
                        321,
                        new byte[]
                {
                    100, 200, 201
                }))
                .Return(packedHash);

                _secretVerifier = new SecureHashAwareSecretVerifier(packedHashConverter, secureHasher);
            }
            protected override void Arrange()
            {
                var packedHashConverter = new PackedHashConverter();

                var originalHashAlgorithm = 1495316179;

                var packedHash = new PackedHash
                {
                    Format        = 0,
                    HashAlgorithm = originalHashAlgorithm,
                    HashBytes     = new byte[]
                    {
                        246, 198, 84, 57, 46, 87, 69, 64, 36, 89, 195, 42, 154,
                        103, 212, 113, 134, 129, 0, 29, 59, 36, 38, 212, 67, 32,
                        67, 113, 96, 103, 22, 129
                    },
                    Iterations = 100,
                    Salt       = new byte[] { 5, 8, 4, 2, 3, 6, 12, 34 }
                };

                _configProvider = new DefaultHashConfigurationProvider();

                _apiClientSecret = new ApiClientSecret
                {
                    IsHashed = true,

                    // GetHashCode is consistent
                    Secret = "ANO2IFlkAAAACAAAAAUIBAIDBgwi9sZUOS5XRUAkWcMqmmfUcYaBAB07JCbUQyBDcWBnFoE="
                };

                _apiClientSecretProvider = Stub <IApiClientSecretProvider>();

                var secureHasher   = new Pbkdf2HmacSha1SecureHasher();
                var originalHasher = A.Fake <ISecureHasher>();

                A.CallTo(() => originalHasher.AlgorithmHashCode).Returns(originalHashAlgorithm);
                A.CallTo(() => originalHasher.ComputeHash(A <string> ._, A <int> ._, A <int> ._, A <byte[]> ._)).Returns(packedHash);

                var next = new SecureHashAwareSecretVerifier(
                    packedHashConverter, new SecureHasherProvider(
                        new List <ISecureHasher>
                {
                    secureHasher,
                    originalHasher
                }));

                _securePackedHashProvider = Stub <ISecurePackedHashProvider>();

                _autoUpgradingHashedSecretVerifierDecorator = new AutoUpgradingHashedSecretVerifierDecorator(
                    _apiClientSecretProvider, next, packedHashConverter, _securePackedHashProvider, _configProvider);
            }
 protected override void Arrange()
 {
     _expectedPackedHash = new PackedHash
     {
         Format        = 1,
         HashAlgorithm = 24,
         HashBytes     = new byte[]
         {
             1,
             2
         },
         Iterations = int.MaxValue,
         Salt       = new byte[]
         {
             5,
             8,
             4,
             2
         }
     };
 }
예제 #6
0
            protected override void Arrange()
            {
                var packedHashConverter = new PackedHashConverter();

                var packedHash = new PackedHash
                {
                    Format        = 0,
                    HashAlgorithm = "GOOD".GetHashCode(), // simulation of a hash routine that used GetHashCode
                    HashBytes     = new byte[]
                    {
                        246, 198, 84, 57, 46, 87, 69, 64, 36, 89, 195, 42, 154,
                        103, 212, 113, 134, 129, 0, 29, 59, 36, 38, 212, 67, 32,
                        67, 113, 96, 103, 22, 129
                    },
                    Iterations = 100,
                    Salt       = new byte[] { 5, 8, 4, 2, 3, 6, 12, 34 }
                };

                _configProvider = new DefaultHashConfigurationProvider();

                _apiClientSecret = new ApiClientSecret
                {
                    IsHashed = true,

                    // GetHashCode is consistent
                    Secret = "ANO2IFlkAAAACAAAAAUIBAIDBgwi9sZUOS5XRUAkWcMqmmfUcYaBAB07JCbUQyBDcWBnFoE="
                };

                _apiClientSecretProvider = Stub <IApiClientSecretProvider>();

                var secureHasher = new Pbkdf2HmacSha1SecureHasher(null);
                var next         = new SecureHashAwareSecretVerifier(packedHashConverter, secureHasher);

                _securePackedHashProvider = Stub <ISecurePackedHashProvider>();

                _autoUpgradingHashedSecretVerifierDecorator = new AutoUpgradingHashedSecretVerifierDecorator(
                    _apiClientSecretProvider, next, packedHashConverter, _securePackedHashProvider, _configProvider);
            }
예제 #7
0
            protected override void Arrange()
            {
                var packedHash = new PackedHash
                {
                    Format        = 1,
                    HashAlgorithm = 123,
                    HashBytes     = new byte[]
                    {
                        111,
                        222,
                        200
                    },
                    Iterations = 321,
                    Salt       = new byte[]
                    {
                        100,
                        200,
                        201
                    }
                };

                var packedHashConverter = Stub <IPackedHashConverter>();

                A.CallTo(() => packedHashConverter.GetPackedHash("MyHashedSecret"))
                .Returns(packedHash);

                var secureHasher = Stub <ISecureHasher>();

                A.CallTo(() => secureHasher.AlgorithmHashCode).Returns(123);
                A.CallTo(() => secureHasher.ComputeHash(A <string> ._, A <int> ._, A <int> ._, A <byte[]> ._)).Returns(packedHash);

                _secretVerifier = new SecureHashAwareSecretVerifier(
                    packedHashConverter, new SecureHasherProvider(new List <ISecureHasher> {
                    secureHasher
                }));
            }
 protected override void Act()
 {
     _actualResult = _secureHasher.ComputeHash(null, 1234, 0, null);
 }
 protected override void Act()
 {
     _actualResult = _secureHasher.ComputeHash(Secret, _hashAlgorithm, 10000, _salt);
 }
 protected override void Act()
 {
     _actualResult = _secureHasher.ProcessRequest(_request);
 }