public void SignIn(TBody body) { // 获取 密钥 string secret = SecretBuilder.Build(); if (string.IsNullOrWhiteSpace(secret)) { throw new Exception("应用程序密钥(AppSecret)为空或null"); } ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); cookieClient.SetCookie(AuthConfigProvider.AuthConfig.CookieName, body.SerializeObject(), AuthConfigProvider.AuthConfig.Expires, value => { ICryptor cryptor = new DesCryptor(SecretBuilder.AppKey, secret); return(cryptor.Encrypt(value)); }); }
public void SignIn(TBody body) { // 获取 密钥 string secret = SecretBuilder.Build(); if (string.IsNullOrWhiteSpace(secret)) { throw new Exception("应用程序密钥(AppSecret)为空或null"); } // 生成加密token; IAlgorithmFactory algorithmFactory = new HMACSHAAlgorithmFactory(); IJwtAlgorithm algorithm = algorithmFactory.Create(AuthConfigProvider.AuthConfig.JwtAlgorithmType); IJsonSerializer serializer = new JsonNetSerializer(); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder); string token = encoder.Encode(body, secret); // 写入Cookie ICookieFactory cookieFactory = new CookieFactory(); ICookieClient cookieClient = cookieFactory.Create(); cookieClient.SetCookie(AuthConfigProvider.AuthConfig.CookieName, token, AuthConfigProvider.AuthConfig.Expires); }