public void opInequality_SecureHash_SecureHashSame()
        {
            var obj       = new SecureHash("XbAH5ybjSkZt+Q==");
            var comparand = obj;

            Assert.False(obj != comparand);
        }
Exemple #2
0
        public static SecureHash Encrypt(string plaintext,
                                         Salt salt)
        {
            if (null == plaintext)
            {
                throw new ArgumentNullException("plaintext");
            }

            if (null == salt)
            {
                throw new ArgumentNullException("salt");
            }

            var bytes = new byte[plaintext.Length + salt.ToBytes().Length];

            Encoding.UTF8.GetBytes(plaintext).CopyTo(bytes, 0);
            salt.ToBytes().CopyTo(bytes, plaintext.Length);

            SecureHash result;

            using (HashAlgorithm algorithm = new SHA256Managed())
            {
                result = new SecureHash(algorithm.ComputeHash(bytes));
            }

            return(result);
        }
        public void opImplicit_string_SecureHash()
        {
            const string expected = "XbAH5ybjSkZt+Q==";
            string       actual   = new SecureHash(expected);

            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public static SecureHash Encrypt(string plaintext,
                                         Salt salt)
        {
            if (null == plaintext)
            {
                throw new ArgumentNullException("plaintext");
            }

            if (null == salt)
            {
                throw new ArgumentNullException("salt");
            }

            var bytes = new byte[plaintext.Length + salt.ToBytes().Length];
            Encoding.UTF8.GetBytes(plaintext).CopyTo(bytes, 0);
            salt.ToBytes().CopyTo(bytes, plaintext.Length);

            SecureHash result;
            using (HashAlgorithm algorithm = new SHA256Managed())
            {
                result = new SecureHash(algorithm.ComputeHash(bytes));
            }

            return result;
        }
        public void opEquality_SecureHash_SecureHashFalse()
        {
            var        obj       = new SecureHash("XbAH5ybjSkZt+Q==");
            SecureHash comparand = SecureHash.Encrypt("plaintext", new Salt());

            Assert.False(obj == comparand);
        }
        public void op_Equals_objectString()
        {
            const string value = "XbAH5ybjSkZt+Q==";
            var          obj   = new SecureHash(value);

            Assert.False(obj.Equals(value));
        }
        public void op_ToString()
        {
            const string expected = "XbAH5ybjSkZt+Q==";
            var          actual   = new SecureHash(expected).ToString();

            Assert.Equal(expected, actual);
        }
        public void opEquality_SecureHash_SecureHashSame()
        {
            var        obj       = new SecureHash("XbAH5ybjSkZt+Q==");
            SecureHash comparand = obj;

            Assert.True(obj == comparand);
        }
        public void op_Equals_objectSame()
        {
            var obj       = SecureHash.Encrypt("plaintext", new Salt());
            var comparand = obj;

            Assert.True(obj.Equals(comparand));
        }
        public void op_Equals_objectFalse()
        {
            var obj       = SecureHash.Encrypt("plaintext", new Salt());
            var comparand = new SecureHash("XbAH5ybjSkZt+Q==");

            Assert.False(obj.Equals(comparand));
        }
Exemple #11
0
        public void opEquality_SecureHash_SecureHashFalse()
        {
            var obj = new SecureHash("XbAH5ybjSkZt+Q==");
            SecureHash comparand = SecureHash.Encrypt("plaintext", new Salt());

            Assert.False(obj == comparand);
        }
Exemple #12
0
        public void opEquality_SecureHash_SecureHashSame()
        {
            var obj = new SecureHash("XbAH5ybjSkZt+Q==");
            SecureHash comparand = obj;

            Assert.True(obj == comparand);
        }
        public void op_Equals_objectTrue()
        {
            const string value     = "XbAH5ybjSkZt+Q==";
            var          obj       = new SecureHash(value);
            var          comparand = new SecureHash(value);

            Assert.True(obj.Equals(comparand));
        }
        public void opEquality_SecureHash_SecureHashTrue()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var obj       = new SecureHash(value);
            var comparand = new SecureHash(value);

            Assert.True(obj == comparand);
        }
        public void op_GetHashCode()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var expected = value.GetHashCode();
            var actual   = new SecureHash(value).GetHashCode();

            Assert.Equal(expected, actual);
        }
        public void op_Encrypt_string_Salt()
        {
            Salt salt = "XbAH5ybjSkZt+Q==";

            var expected = new SecureHash("4bF4xJX9VVDr+xFMuOWS/9wJLAc7/ByDjW2PgPp5YLc=");
            var actual   = SecureHash.Encrypt("plaintext", salt);

            Assert.Equal(expected, actual);
        }
        public void op_Encrypt_stringEmpty_Salt()
        {
            Salt salt = "XbAH5ybjSkZt+Q==";

            var expected = new SecureHash("2uI+DajQR+GeYNTccNcDjoE5UtXbF6Jr+kVtE4vcNn4=");
            var actual   = SecureHash.Encrypt(string.Empty, salt);

            Assert.Equal(expected, actual);
        }
        public void opInequality_SecureHash_SecureHashFalse()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var obj       = new SecureHash(value);
            var comparand = new SecureHash(value);

            Assert.False(obj != comparand);
        }
        public void opImplicit_SecureHash_string()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var        expected = new SecureHash(value);
            SecureHash actual   = value;

            Assert.Equal(expected, actual);
        }
Exemple #20
0
        public void opEquality_SecureHash_SecureHashTrue()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var obj = new SecureHash(value);
            var comparand = new SecureHash(value);

            Assert.True(obj == comparand);
        }
Exemple #21
0
        public void opImplicit_SecureHash_string()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var expected = new SecureHash(value);
            SecureHash actual = value;

            Assert.Equal(expected, actual);
        }
 public void op_Encrypt_string_SaltNull()
 {
     Assert.Throws <ArgumentNullException>(() => SecureHash.Encrypt("plaintext", null));
 }
Exemple #23
0
        public void op_ToString()
        {
            const string expected = "XbAH5ybjSkZt+Q==";
            var actual = new SecureHash(expected).ToString();

            Assert.Equal(expected, actual);
        }
Exemple #24
0
        public void op_GetHashCode()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var expected = value.GetHashCode();
            var actual = new SecureHash(value).GetHashCode();

            Assert.Equal(expected, actual);
        }
Exemple #25
0
        public void op_Equals_objectTrue()
        {
            const string value = "XbAH5ybjSkZt+Q==";
            var obj = new SecureHash(value);
            var comparand = new SecureHash(value);

            Assert.True(obj.Equals(comparand));
        }
Exemple #26
0
        public void op_Equals_objectString()
        {
            const string value = "XbAH5ybjSkZt+Q==";
            var obj = new SecureHash(value);

            Assert.False(obj.Equals(value));
        }
Exemple #27
0
        public void op_Encrypt_stringEmpty_Salt()
        {
            Salt salt = "XbAH5ybjSkZt+Q==";

            var expected = new SecureHash("2uI+DajQR+GeYNTccNcDjoE5UtXbF6Jr+kVtE4vcNn4=");
            var actual = SecureHash.Encrypt(string.Empty, salt);

            Assert.Equal(expected, actual);
        }
Exemple #28
0
        public void opInequality_SecureHash_SecureHashSame()
        {
            var obj = new SecureHash("XbAH5ybjSkZt+Q==");
            var comparand = obj;

            Assert.False(obj != comparand);
        }
Exemple #29
0
        public void opInequality_SecureHash_SecureHashFalse()
        {
            const string value = "XbAH5ybjSkZt+Q==";

            var obj = new SecureHash(value);
            var comparand = new SecureHash(value);

            Assert.False(obj != comparand);
        }
 public void op_Equals_objectNull()
 {
     Assert.False(SecureHash.Encrypt("plaintext", new Salt()).Equals(null));
 }
 public void opEquality_SecureHashNull_SecureHash()
 {
     Assert.False(null == SecureHash.Encrypt("plaintext", new Salt()));
 }
 public void opEquality_SecureHash_SecureHashNull()
 {
     Assert.False(SecureHash.Encrypt("plaintext", new Salt()) == null);
 }
 public void op_Encrypt_stringNull_Salt()
 {
     Assert.Throws <ArgumentNullException>(() => SecureHash.Encrypt(null, new Salt()));
 }
Exemple #34
0
        public void op_Encrypt_string_Salt()
        {
            Salt salt = "XbAH5ybjSkZt+Q==";

            var expected = new SecureHash("4bF4xJX9VVDr+xFMuOWS/9wJLAc7/ByDjW2PgPp5YLc=");
            var actual = SecureHash.Encrypt("plaintext", salt);

            Assert.Equal(expected, actual);
        }
Exemple #35
0
        public void op_Equals_objectFalse()
        {
            var obj = SecureHash.Encrypt("plaintext", new Salt());
            var comparand = new SecureHash("XbAH5ybjSkZt+Q==");

            Assert.False(obj.Equals(comparand));
        }
Exemple #36
0
        public void opImplicit_string_SecureHash()
        {
            const string expected = "XbAH5ybjSkZt+Q==";
            string actual = new SecureHash(expected);

            Assert.Equal(expected, actual);
        }
 public void opInequality_SecureHash_SecureHashNull()
 {
     Assert.True(SecureHash.Encrypt("plaintext", new Salt()).IsNotNull());
 }