Пример #1
0
        public void UnprotectWithDifferentPurposeFails()
        {
            var provider         = ServiceProvider.GetRequiredService <IDataProtectionProvider>();
            var prototector      = provider.CreateProtector("test");
            var secureDataFormat = new SecureDataFormat <string>(new StringSerializer(), prototector);

            string input         = "abcdefghijklmnopqrstuvwxyz0123456789";
            string purpose       = "purpose1";
            var    protectedData = secureDataFormat.Protect(input, purpose);
            var    result        = secureDataFormat.Unprotect(protectedData); // Null other purpose

            Assert.Null(result);

            result = secureDataFormat.Unprotect(protectedData, "purpose2");
            Assert.Null(result);
        }
Пример #2
0
        public void OwinDataHandler(SecureDataFormat <AuthenticationProperties> secure)
        {
            AuthenticationProperties props = new AuthenticationProperties();

            string secured = secure.Protect(props);
            AuthenticationProperties unsecured = secure.Unprotect(secured);

            byte[] decoded = new byte[10];
        }
Пример #3
0
        public void ProtectDataRoundTrips()
        {
            var provider         = ServiceProvider.GetRequiredService <IDataProtectionProvider>();
            var prototector      = provider.CreateProtector("test");
            var secureDataFormat = new SecureDataFormat <string>(new StringSerializer(), prototector);

            string input         = "abcdefghijklmnopqrstuvwxyz0123456789";
            var    protectedData = secureDataFormat.Protect(input);
            var    result        = secureDataFormat.Unprotect(protectedData);

            Assert.Equal(input, result);
        }
Пример #4
0
        public void OwinDataHandler(ITextEncoder encoder, SecureDataFormat <AuthenticationProperties> secure)
        {
            AuthenticationProperties props = new AuthenticationProperties();

            string secured = secure.Protect(props);
            AuthenticationProperties unsecured = secure.Unprotect(secured);

            byte[] decoded = new byte[10];
            string encoded = encoder.Encode(decoded);

            decoded = encoder.Decode(encoded);
        }