public PasswordGenerator( IDerivedKeyFactory derivedPasswordFactory, IDerivedKeyFactory digestFactory,
                           PasswordMaterializer materializer, int digestLength )
 {
     _derivedPasswordFactory = derivedPasswordFactory;
     _digestFactory = digestFactory;
     _materializer = materializer;
     _digestLength = digestLength;
 }
        public void AlphabetNeeds9BytesWith48Symbols( )
        {
            // Set up
            string symbols128 = Enumerable.Repeat( "0123456789ABCDEF", 3 ).Aggregate( ( l, r ) => l + r );
            PasswordMaterializer materializer = new PasswordMaterializer( symbols128 );

            // Exercise
            // Verify
            Assert.That( materializer.BytesNeeded, Is.EqualTo( 9 ) );
        }
        public void AlphabetNeeds8BytesWith16Symbols( )
        {
            // Set up
            const string symbols16 = "0123456789ABCDEF";
            PasswordMaterializer materializer = new PasswordMaterializer( symbols16 );

            // Exercise
            // Verify
            Assert.That( materializer.BytesNeeded, Is.EqualTo( 8 ) );
        }
        public void TestConvertArrayToSymbols16Returns16Characters( )
        {
            // Setup
            const string symbols16 = "0123456789ABCDEF";
            PasswordMaterializer materializer = new PasswordMaterializer( symbols16 );

            byte[ ] input = { 0xA1, 0x22, 0x44, 0x60, 0xE7, 0x01, 0x1A, 0x48 };
            // Exercise
            string symbols = materializer.ToString( input );
            // Verify
            Assert.That( symbols, Is.EqualTo( "1A2244067E10A184" ) );
        }
        public void TestConvertArrayToSymbols64Returns12Characters( )
        {
            // Setup
            const string symbols64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+";
            PasswordMaterializer materializer = new PasswordMaterializer( symbols64 );

            BaseConverter converter = new BaseConverter( 64 );

            byte[ ] input = { 0xA1, 0x22, 0x44, 0x60, 0xE7, 0x01, 0x1A, 0x48, 0xCB };
            byte[ ] convertedBytes = converter.ConvertBytesToDigits( input, 12 );

            string expectedOutput = new string( convertedBytes.Select( b => symbols64[ b ] ).ToArray( ) );
            // Exercise
            string output = materializer.ToString( input );
            // Verify
            Assert.That( output, Is.EqualTo( expectedOutput ) );
        }
 private static PasswordGenerator Sha512Generator( PasswordMaterializer materializer )
 {
     return new PasswordGenerator( new Sha512DerivedKeyFactory( ( s, p ) => InternalSalt.Concat( p ).Concat( s ).ToArray( ) ),
                                   new Sha512DerivedKeyFactory( ( s, p ) => s.Concat( p ).ToArray( ) ),
                                   materializer, 64 );
 }
 private static PasswordGenerator Pbkdf2Generator( PasswordMaterializer materializer )
 {
     return new PasswordGenerator( new Pbkdf2DerivedKeyFactory( 1000 ), new Pbkdf2DerivedKeyFactory( 1000 ), materializer, 32 );
 }