Esempio n. 1
0
 /// <summary>
 /// 从cookie中拿到信息并解密
 /// </summary>
 /// <param name="accessor"></param>
 /// <returns></returns>
 public static string GetCookie(this HttpContext httpContext, string cookieKey = CookieKey)
 {
     if (string.IsNullOrWhiteSpace(cookieKey))
     {
         return("");
     }
     return(DEncrypt.Decrypt(httpContext.Request.Cookies[cookieKey]));
 }
Esempio n. 2
0
        private static void GetConfigValue()
        {
            var mailConfig = BaseCore.Configuration.GetSection("AppSettings").GetSection("MailConfig");

            foreach (var config in mailConfig.GetChildren())
            {
                Console.WriteLine(config.Value + "——" + DEncrypt.Decrypt(config.Value));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 将信息加密保存到cookie
        /// </summary>
        /// <param name="accessor"></param>
        /// <param name="cookieValue"></param>
        /// <returns></returns>
        public static bool SetCookie(this HttpContext httpContext, string cookieValue, string cookieKey = CookieKey)
        {
            if (string.IsNullOrWhiteSpace(cookieValue) || string.IsNullOrWhiteSpace(cookieKey))
            {
                return(false);
            }
            httpContext.Response.Cookies.Append(CookieKey, DEncrypt.Encrypt(cookieValue), new CookieOptions()
            {
                Expires = DateTimeOffset.Now.AddHours(1)
            });

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// 读取配置文件后,异步发送邮件
        /// </summary>
        /// <param name="toMail">收件地址</param>
        /// <param name="subj">主题</param>
        /// <param name="bodys">正文</param>
        /// <param name="enableSsl">是否启用ssl</param>
        /// <param name="isEncrypted">配置是否加密</param>
        public static async Task SendMailAsync(string toMail, string subj, string bodys, bool enableSsl = false, bool isEncrypted = true)
        {
            var mailConfig = BaseCore.Configuration.GetSection("AppSettings").GetSection("MailConfig");
            var smtpServer = mailConfig["smtp"];
            var userName   = mailConfig["account"];
            var pwd        = mailConfig["pwd"];
            var nickName   = mailConfig["nickName"];
            var fromMail   = mailConfig["fromMail"];

            if (isEncrypted)
            {
                smtpServer = DEncrypt.Decrypt(smtpServer);
                userName   = DEncrypt.Decrypt(userName);
                pwd        = DEncrypt.Decrypt(pwd);
                nickName   = DEncrypt.Decrypt(nickName);
                fromMail   = DEncrypt.Decrypt(fromMail);
            }

            await Task.Run(() => {
                SendMail(smtpServer, enableSsl, userName, pwd, nickName, fromMail, toMail, subj, bodys);
            });
        }