コード例 #1
0
        public CookieBasedSessionsFixture()
        {
            this.fakeEncryptionProvider = A.Fake<IEncryptionProvider>();
            this.fakeHmacProvider = A.Fake<IHmacProvider>();
            this.cookieStore = new CookieBasedSessions(this.fakeEncryptionProvider, this.fakeHmacProvider, new Fakes.FakeObjectSerializer());

            this.rijndaelEncryptionProvider = new RijndaelEncryptionProvider(new PassphraseKeyGenerator("password", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 1000));
            this.defaultHmacProvider = new DefaultHmacProvider(new PassphraseKeyGenerator("anotherpassword", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 1000));
        }
コード例 #2
0
        public void Should_return_hmac_array()
        {
            var provider = new DefaultHmacProvider(new RandomKeyGenerator());

            var result = provider.GenerateHmac("some data");

            result.ShouldNotBeNull();
            result.Length.ShouldBeGreaterThan(0);
        }
コード例 #3
0
        public CookieBasedSessionsFixture()
        {
            this.fakeEncryptionProvider = A.Fake<IEncryptionProvider>();
            this.fakeHmacProvider = A.Fake<IHmacProvider>();
            this.cookieStore = new CookieBasedSessions(this.fakeEncryptionProvider, this.fakeHmacProvider, new Fakes.FakeSessionObjectFormatter());

            this.rijndaelEncryptionProvider = new RijndaelEncryptionProvider(new PassphraseKeyGenerator("password"));
            this.defaultHmacProvider = new DefaultHmacProvider(new PassphraseKeyGenerator("anotherpassword"));
        }
コード例 #4
0
        public void Should_return_array_the_same_size_as_hash_length()
        {
            var provider = new DefaultHmacProvider(new RandomKeyGenerator());
            var hashLength = provider.HmacLength;

            var result = provider.GenerateHmac("some data");

            result.Length.ShouldEqual(hashLength);
        }
コード例 #5
0
        /// <summary>
        /// Configures authentication for the specified <paramref name="pipelines"/>
        /// using the specified <paramref name="userMapper"/>.
        /// </summary>
        /// <param name="pipelines"></param>
        /// <param name="userMapper"></param>
        public static void RegisterAuthentication(IPipelines pipelines, IUserMapper userMapper)
        {
            Verify.NotNull(userMapper, nameof(userMapper));

            var keyGenerator = new PassphraseKeyGenerator(KEY, Salt);

            var encryptionProvider = new RijndaelEncryptionProvider(keyGenerator);
            var hmacProvider = new DefaultHmacProvider(keyGenerator);
            var cryptographyConfiguration = new CryptographyConfiguration(encryptionProvider, hmacProvider);

            var formsConfiguration = new FormsAuthenticationConfiguration(cryptographyConfiguration)
            {
                RedirectUrl = "~/sign-in",
                UserMapper = userMapper
            };

            FormsAuthentication.Enable(pipelines, formsConfiguration);
        }