예제 #1
0
        public void constructor_with_string_should_initialize_instance(
            [Values("", "a", "ab", "abc")] string value)
        {
            var result = new PasswordEvidence(value);

            var decryptedPassword = new DecryptedSecureString(result.SecurePassword);

            decryptedPassword.GetChars().Should().Equal(value);
        }
예제 #2
0
        public void SecurePassword_should_return_expected_result(
            [Values("", "a", "ab", "abc")] string value)
        {
            var subject = CreateSubject(value);

            var result = subject.SecurePassword;

            var decryptedPassword = new DecryptedSecureString(result);

            decryptedPassword.GetChars().Should().Equal(value);
        }
        private static string GetSignature(string stringToSign, SecureString secretAccessKey, string date, string region, string service)
        {
            using (var decryptedSecureString = new DecryptedSecureString(secretAccessKey))
            {
                var aws4SecretAccessKeyChars = "AWS4".Concat(decryptedSecureString.GetChars()).ToArray();
                var aws4SecretAccessKeyBytes = Encoding.ASCII.GetBytes(aws4SecretAccessKeyChars);
                var kDateBlock = Hmac256(aws4SecretAccessKeyBytes, Encoding.ASCII.GetBytes(date));
                Array.Clear(aws4SecretAccessKeyChars, 0, aws4SecretAccessKeyChars.Length);
                Array.Clear(aws4SecretAccessKeyBytes, 0, aws4SecretAccessKeyBytes.Length);
                var kRegionBlock  = Hmac256(kDateBlock, Encoding.ASCII.GetBytes(region));
                var kServiceBlock = Hmac256(kRegionBlock, Encoding.ASCII.GetBytes(service));
                var kSigningBlock = Hmac256(kServiceBlock, Encoding.ASCII.GetBytes("aws4_request"));

                return(BsonUtils.ToHexString(Hmac256(kSigningBlock, Encoding.ASCII.GetBytes(stringToSign))));
            }
        }
예제 #4
0
        // private methods
        private bool Equals(SecureString x, SecureString y)
        {
            if (object.ReferenceEquals(x, y))
            {
                return(true);
            }

            if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null))
            {
                return(false);
            }
            using (var dx = new DecryptedSecureString(x))
                using (var dy = new DecryptedSecureString(y))
                {
                    var xchars = dx.GetChars();
                    var ychars = dy.GetChars();
                    return(Equals(xchars, ychars));
                }
        }