Esempio n. 1
0
        public void HashKeySalted_Serialization_Binary()
        {
            var key1            = HashKeySalted.Create();
            var plainData       = Guid.NewGuid().ToByteArray();
            var key1Hash        = key1.Hash(plainData);
            var serializedKey   = Serialize.To.Binary(key1);
            var deserializedKey = Serialize.From.Binary <HashKeySalted>(serializedKey);
            var key2Hash        = deserializedKey.Hash(plainData);

            var key1HashResult = CryptoUtils.FromBytes(key1Hash, StringFormat.Base64);
            var key2HashResult = CryptoUtils.FromBytes(key2Hash, StringFormat.Base64);

            Assert.AreEqual <string>(key1HashResult, key2HashResult);
        }
Esempio n. 2
0
        public void HashSaltedTests_DefaultConstructor()
        {
            //-------------------------------------------------------
            // arrange
            //-------------------------------------------------------
            var key       = HashKeySalted.Create();
            var plainData = Guid.NewGuid().ToByteArray();

            //-------------------------------------------------------
            // act
            //-------------------------------------------------------
            var firstHash  = key.Hash(plainData);
            var secondHash = key.Hash(plainData);

            //-------------------------------------------------------
            // assert
            //-------------------------------------------------------
            var firstResult  = Encoding.Unicode.GetString(firstHash);
            var secondResult = Encoding.Unicode.GetString(secondHash);

            Assert.AreEqual(firstResult, secondResult);
        }
Esempio n. 3
0
        public void HashKeySaltedTests_ParameterizedConstructor()
        {
            //-------------------------------------------------------
            // arrange
            //-------------------------------------------------------
            var key1      = HashKeySalted.Create();
            var key2      = HashKeySalted.Create(Crypto.HashModesSalted.HMACSHA256, key1.Salt);
            var plainData = Guid.NewGuid().ToByteArray();

            //-------------------------------------------------------
            // act
            //-------------------------------------------------------
            var firstHash  = key1.Hash(plainData);
            var secondHash = key2.Hash(plainData);

            //-------------------------------------------------------
            // assert
            //-------------------------------------------------------
            var firstResult  = Encoding.Unicode.GetString(firstHash);
            var secondResult = Encoding.Unicode.GetString(secondHash);

            Assert.AreEqual(firstResult, secondResult);
        }