コード例 #1
0
        public AuthenticationTicket Unprotect(string protectedText)
        {
            var prottData = JsonConvert.DeserializeObject <ProtectedData>(TripleDESCryptoService.decryptFromBase64(protectedText));

            var identity = new ClaimsIdentity(prottData.claims.Select(c => new Claim(c.type, c.value)),
                                              AuthenticationType.Beaer, ProtectedData.nameType, ProtectedData.roleType);

            var props = new AuthenticationProperties()
            {
                ExpiresUtc = prottData.properties.expiresUtc, IssuedUtc = prottData.properties.issuedUtc
            };

            return(new AuthenticationTicket(identity, props));
        }
コード例 #2
0
        public string Protect(AuthenticationTicket data)
        {
            var prottData = new ProtectedData()
            {
                properties = new ProtectedData.AuthenticationProperties()
                {
                    expiresUtc = data.Properties.ExpiresUtc,
                    issuedUtc  = data.Properties.IssuedUtc
                }
            };

            prottData.claims = data.Identity.Claims.Select(c => new ProtectedData.Claim()
            {
                type = c.Type, value = c.Value
            });

            return(TripleDESCryptoService.encryptToBase64(JsonConvert.SerializeObject(prottData)));
        }