Exemplo n.º 1
0
        public void WhenAuthorizingAnExistingWrongMasterKey_ADifferentHmacShouldBeComputed()
        {
            // Given
            var existingMasterKey = new MasterKey("Wrong Password", KnownSalt, KnownIterations, CreatePbkdf2());

            // When
            var existingAuthorization = new Authorization(existingMasterKey, KnownInitializationVector, CreateAes(), CreateHmacSha256());

            // Then
            existingAuthorization.Hmac.Should().NotBeEquivalentTo(KnownHmac);
        }
Exemplo n.º 2
0
        public void WhenCreatingANewAuthorizationTwiceWithTheSameMasterKey_ADifferentHashShouldBeGeneratedBecauseTheInitializationVectorIsDifferent()
        {
            // Given
            var newMasterKey = new MasterKey(KnownPassword, KnownIterations, CreatePbkdf2());

            // When
            var firstNewAuthorization = new Authorization(newMasterKey, CreateAes(), CreateHmacSha256());
            var secondNewAuthorization = new Authorization(newMasterKey, CreateAes(), CreateHmacSha256());

            // Then
            firstNewAuthorization.Hmac.Should().NotBeEquivalentTo(secondNewAuthorization.Hmac);
        }
Exemplo n.º 3
0
        public void WhenAuthorizingAnExistingCorrectMasterKey_TheCorrectHmacShouldBeComputer()
        {
            // Given
            var existingMasterKey = new MasterKey(KnownPassword, KnownSalt, KnownIterations, CreatePbkdf2());

            // When
            var existingAuthorization = new Authorization(existingMasterKey, KnownInitializationVector, CreateAes(), CreateHmacSha256());

            // Then
            existingAuthorization.InitializationVector.Should().BeEquivalentTo(KnownInitializationVector);
            existingAuthorization.Hmac.Should().BeEquivalentTo(KnownHmac);
        }
Exemplo n.º 4
0
        public void WhenCreatingANewAuthorization_ItShouldBeCreated()
        {
            // Given
            var newMasterKey = new MasterKey(KnownPassword, KnownIterations, CreatePbkdf2());

            // When
            var newAuthorization = new Authorization(newMasterKey, CreateAes(), CreateHmacSha256());

            // Then
            newAuthorization.InitializationVector.Length.Should().Be(Aes.BlockSizeInBits / 8);
            newAuthorization.InitializationVector.Should().NotBeEmpty();
            newAuthorization.Hmac.Length.Should().Be(HmacSha256.HmacSizeInBits / 8);
            newAuthorization.Hmac.Should().NotBeEmpty();
        }
Exemplo n.º 5
0
        public void WhenCreatingTwiceTheAuthorizationWithTheSameInitializationVector_ItShouldBeTheSame()
        {
            // Given
            var newMasterKey = new MasterKey(KnownPassword, KnownIterations, CreatePbkdf2());

            // When
            var newAuthorization = new Authorization(newMasterKey, CreateAes(), CreateHmacSha256());
            var existingAuthorization = new Authorization(newMasterKey, newAuthorization.InitializationVector,
                CreateAes(), CreateHmacSha256());

            // Then
            newAuthorization.Hmac.Should().BeEquivalentTo(existingAuthorization.Hmac);
        }