Exemplo n.º 1
0
 protected void btnSendEmail_OnClick(object sender, EventArgs e)
 {
     try
     {
         var user = UserBll.GetPasswordByEmail(tbxEmail.Text.Trim());
         if (user == null)
         {
             WebUtil.Alert("Email doesn't exist.");
             return;
         }
         var host          = SysConfig.Instance.EmailHost;
         var emailPassword = DESUtil.Decrypt(SysConfig.Instance.EmailPassword);
         var email         = SysConfig.Instance.Email;
         var client        = new SmtpClient(host);
         client.UseDefaultCredentials = false;
         client.Credentials           = new NetworkCredential(email, emailPassword);
         client.DeliveryMethod        = SmtpDeliveryMethod.Network;
         var addressFrom = new MailAddress(email, "");
         var addressTo   = new MailAddress(tbxEmail.Text.Trim(), "Get Password");
         var message     = new MailMessage(addressFrom, addressTo);
         message.Subject      = "Get Password";
         message.Body         = "Dear Sir or Madam,it's from Yelleat.Your password is '" + DESUtil.Decrypt(user.Password) + "' .Keep it please.";
         message.Sender       = new MailAddress(email);
         message.BodyEncoding = System.Text.Encoding.UTF8;
         message.IsBodyHtml   = true;
         client.Send(message);
         WebUtil.Alert("Email is sent Successfully.");
     }
     catch
     {
         WebUtil.Alert("Email is sent failed", this.Page);
     }
 }
Exemplo n.º 2
0
        static SysConfig()
        {
            var file = HttpContext.Current.Server.MapPath("/System.config.xml");

            if (!File.Exists(file))
            {
                using (var fs = File.Create(file))
                {
                    _systemConfig = new SysConfig();
                    _systemConfig.EmailPassword = "******";
                    _systemConfig.Email         = "*****@*****.**";
                    _systemConfig.EmailAccount  = "yelleat";
                    _systemConfig.EmailHost     = "smtp.exmail.qq.com";
                    var serializer = new XmlSerializer(typeof(SysConfig));
                    var writer     = new StreamWriter(fs);
                    serializer.Serialize(writer, _systemConfig);
                    writer.Close();
                }
            }
            else
            {
                var xml = new XmlSerializer(typeof(SysConfig));
                _systemConfig           = (SysConfig)xml.Deserialize(new FileStream(file, FileMode.OpenOrCreate));
                _systemConfig._password = DESUtil.Decrypt(_systemConfig._password);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取明文连接字符串
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <returns>明文连接字符串</returns>
        public string GetPlaintextConnectionString(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString) || !ConnectionEncrypt)
            {
                return(connectionString);
            }

            return(DESUtil.Decrypt(connectionString));
        }
Exemplo n.º 4
0
    void Decry()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();
        var text = DESUtil.Decrypt(toDecry, key, iv);

        sw.Stop();
        Debug.Log(sw.ElapsedMilliseconds);
        Debug.Log(text);
    }
        /// <summary>
        /// 获取默认的连接字符串
        /// </summary>
        /// <returns>默认的连接字符串</returns>
        protected override string GetDefaultConnectionString()
        {
            var connString = AppConfig["MessageQueue:RabbitConnectionString"];

            if (string.IsNullOrWhiteSpace(connString))
            {
                return(connString);
            }

            return(ConfigUtil.ConnectionEncryption ? DESUtil.Decrypt(connString, AppConfig["DES:Key"], AppConfig["DES:IV"]) : connString);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据键获取连接字符串集合
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>连接字符串集合</returns>
        private string[] GetConnectionStrings(string key)
        {
            string value = AppConfig[key];

            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            string conns = ConnectionEncryption ? DESUtil.Decrypt(value, PlatformTool.AppConfig["DES:Key"], PlatformTool.AppConfig["DES:IV"]) : value;

            return(conns.Split('|'));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 点击解密按钮
        /// </summary>
        /// <param name="sender">引发对象</param>
        /// <param name="e">事件参数</param>
        private void btnDecode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCiphertext.Text))
            {
                MessageBox.Show("请输入密文");
                return;
            }

            try
            {
                txtPlaintext.Text = DESUtil.Decrypt(txtCiphertext.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 8
0
        public override void OnSuccess(WWW www)
        {
            Dictionary <string, object> plist = Plist.readPlist(DESUtil.Decrypt(www.bytes, FileUtil.sKey)) as Dictionary <string, object>;

            _sgAds = DictionaryUtil.GetDictionaryValue(plist, "Data", "SGAds");
            List <object> InterstitialAds  = DictionaryUtil.GetListValue(_sgAds, "InterstitialAds");
            Dictionary <string, object> v1 = InterstitialAds [0] as  Dictionary <string, object>;

            Debug.Log("InterstitialAdConfig   .....  OnSuccess");
            InterstitialAdLoader interstitialAdLoader = new InterstitialAdLoader(DictionaryUtil.GetStringValue(v1, "", IMAGE_URL), DictionaryUtil.GetStringValue(v1, "", APP_NAME), DictionaryUtil.GetStringValue(v1, "", APP_URL));

            isOn = true;
            interstitialAdLoader.StartLoader();
            Dictionary <string, object> BannerAds = DictionaryUtil.GetDictionaryValue(_sgAds, BANNER_ADS);

            iconsImageLoader = new SimpleZipDownloader(DictionaryUtil.GetStringValue(BannerAds, "", ICONS_URL), OnIconsLoad, false);
            iconsImageLoader.StartLoader();
            _bannerInfos = DictionaryUtil.GetListValue(BannerAds, APPS_INFO);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 创建连接且打开
        /// </summary>
        /// <param name="connectionStringConfigName">连接字符串配置名称</param>
        /// <param name="messageQueueFilePath">消息队列文件路径</param>
        /// <param name="dataContentType">数据内容类型。只支持JSON和XML</param>
        /// <returns>连接</returns>
        public static IMessageQueueConnection CreateAndOpen(string connectionStringConfigName = null, string messageQueueFilePath = null, DataContentType dataContentType = DataContentType.JSON)
        {
            if (!(dataContentType == DataContentType.JSON || dataContentType == DataContentType.XML))
            {
                throw new NotSupportedException("数据内容类型只支持JSON或XML");
            }

            var conn = new RabbitAutoRecoveryConnection();

            if (string.IsNullOrWhiteSpace(connectionStringConfigName))
            {
                conn.Open();
            }
            else
            {
                var connString = PlatformTool.AppConfig[connectionStringConfigName];
                if (ConfigUtil.ConnectionEncryption)
                {
                    connString = DESUtil.Decrypt(connString, PlatformTool.AppConfig["DES:Key"], PlatformTool.AppConfig["DES:IV"]);
                }
                conn.Open(connString);
            }

            if (!string.IsNullOrWhiteSpace(messageQueueFilePath))
            {
                var rabbitConn = conn.ProtoConnection as RabbitConnection;
                var messageQueueInfoFactory = new RabbitMessageQueueInfoConfigFactory();
                rabbitConn.MessageQueueInfoFactory = messageQueueInfoFactory;

                if (dataContentType == DataContentType.JSON)
                {
                    messageQueueInfoFactory.MessageQueueReader = new RabbitMessageQueueJson(messageQueueFilePath);
                }
                else
                {
                    messageQueueInfoFactory.MessageQueueReader = new RabbitMessageQueueXml(messageQueueFilePath);
                }
            }

            return(conn);
        }
Exemplo n.º 10
0
 public static string DecryptDES(this string str)
 {
     return(DESUtil.Decrypt(str));
 }
Exemplo n.º 11
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (!actionContext.Request.Headers.Contains("signature"))
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                              "signature required");
            }
            else
            {
                var des = new DESUtil();
                try
                {
                    string decrypted = des.Decrypt(actionContext.Request.Headers.GetValues("signature").First(),
                                                   DESUtil.SECRET_TIMESTAMP_NONCE_AUTH);
                    if (decrypted.Length < 11) //10位TimeStamp+Nonce
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                                      "invalid signature string");
                    }
                    else
                    {
                        long timeStamp = 0;
                        int  nonce     = 0;
                        long.TryParse(decrypted.Substring(0, 10), out timeStamp);
                        int.TryParse(decrypted.Substring(10), out nonce);
                        if (timeStamp == 0 || nonce == 0)
                        {
                            actionContext.Response =
                                actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                     "invalid signature");
                        }
                        else
                        {
                            // Get the request lifetime scope so you can resolve services.
                            var requestScope = actionContext.Request.GetDependencyScope();

                            // Resolve the service you want to use.
                            var db = requestScope.GetService(typeof(YJYEntities)) as YJYEntities;

                            var record =
                                db.TimeStampNonces.FirstOrDefault(o => o.Nonce == nonce && o.TimeStamp == timeStamp);
                            if (record == null || record.UsedAt != null)
                            {
                                actionContext.Response =
                                    actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                         "signature unauthorized");
                            }
                            else
                            {
                                record.UsedAt = DateTime.UtcNow;
                                db.SaveChanges();
                            }
                        }
                    }
                }
                catch
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                                  "signature checking failed");
                }
            }

            base.OnAuthorization(actionContext);
        }