Example #1
0
        /// <summary>
        ///  获取jssdk签名信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task <WxJsSdkSignatureResp> GetJsSdkSignature(string url)
        {
            var ticketRes = await GetJsTicketFromCacheAsync(WxJsTicketType.jsapi);

            if (!ticketRes.IsSuccess())
            {
                return(new WxJsSdkSignatureResp().WithResp(ticketRes));// ticketRes.ConvertToResultInherit<WxJsSdkSignatureResp>();
            }

            var resp = new WxJsSdkSignatureResp
            {
                app_id    = ApiConfig.AppId,
                noncestr  = GenerateNonceStr(),
                timestamp = DateTime.Now.ToLocalSeconds()
            };


            var signStr = new StringBuilder();

            signStr.Append("jsapi_ticket=").Append(ticketRes.ticket);
            signStr.Append("&noncestr=").Append(resp.noncestr);
            signStr.Append("&timestamp=").Append(resp.timestamp);
            if (!string.IsNullOrEmpty(url))
            {
                signStr.Append("&url=").Append(url);
            }

            resp.signature = Sha1.Encrypt(signStr.ToString());

            return(resp);
        }
Example #2
0
        protected override void button1_Click(object sender, EventArgs e)
        {
            BllStatusLib statusLib = new BllStatusLib();

            foreach (int item in checkedListBox3.CheckedIndices)
            {
                statusLib.SelectedEntities.Add(new BllSelectedStatus {
                    Entity = Statuses[item]
                });
            }
            BllEventTypeLib eventTypeLib = new BllEventTypeLib();

            foreach (int item in checkedListBox2.CheckedIndices)
            {
                eventTypeLib.SelectedEntities.Add(new BllSelectedEntity <BllEventType> {
                    Entity = EventTypes[item]
                });
            }
            Entity = new BllUser
            {
                Fullname     = textBox1.Text,
                Login        = textBox2.Text,
                Password     = Sha1.Encrypt(textBox3.Text),
                Group        = Groups[comboBox1.SelectedIndex],
                StatusLib    = statusLib,
                EventTypeLib = eventTypeLib
            };
            Entity = server.CreateUser((BllUser)Entity);
            base.button1_Click(sender, e);
        }
Example #3
0
        /// <summary>
        /// 验证签名方法
        /// </summary>
        /// <param name="token"></param>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <param name="strEncryptMsg"></param>
        /// <returns></returns>
        internal static string GenerateSignature(string token,
                                                 string timestamp, string nonce, string strEncryptMsg = "")
        {
            var strList = new List <string>()
            {
                token, timestamp, nonce, strEncryptMsg
            };

            strList.Sort();

            var waitEncropyStr = string.Join(string.Empty, strList);

            return(Sha1.Encrypt(waitEncropyStr, Encoding.ASCII));
        }
Example #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     User = new BllUser();
     if ((textBox1.Text == "") || (textBox2.Text == ""))
     {
         MessageBox.Show("Введите логин и пароль");
     }
     else
     {
         User.Login    = textBox1.Text;
         User.Password = Sha1.Encrypt(textBox2.Text);
         Close();
     }
 }
Example #5
0
        /// <summary>
        /// 生成 API Token 信息
        /// </summary>
        /// <returns></returns>
        public List <KeyValuePair <string, string> > GenToken()
        {
            var timestamp = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).Ticks.ToString();
            var nonce     = (new Random((int)(DateTime.Now.Ticks))).Next(0, 999999999).ToString("D9");
            var data      = new List <string> {
                timestamp, nonce, _apiToken
            };

            data.Sort();
            var sign       = Sha1.Encrypt(string.Join("", data.ToArray())).Replace("-", "").ToLower();
            var resultList = new List <KeyValuePair <string, string> >();

            resultList.Add(new KeyValuePair <string, string>("signature", sign));
            resultList.Add(new KeyValuePair <string, string>("timestamp", timestamp));
            resultList.Add(new KeyValuePair <string, string>("nonce", nonce));
            return(resultList);
        }
Example #6
0
        /// <summary>
        /// 获取一个Token
        /// </summary>
        /// <returns>Token</returns>
        public QfToken GetToken()
        {
            var timestamp = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).Ticks;
            var nonce     = (new Random((int)(DateTime.Now.Ticks))).Next(10000000, 99999999).ToString();
            var data      = new List <string> {
                _tokenKey, timestamp.ToString(), nonce
            };

            data.Sort();
            var tokenCode = Sha1.Encrypt(string.Join("", data.ToArray()));
            var token     = new QfToken()
            {
                TokenID = _tokenId, TokenCode = tokenCode, Timestamp = timestamp, Nonce = nonce
            };

            return(token);
        }
        protected override void button1_Click(object sender, EventArgs e)
        {
            BllUser User = (BllUser)Entity;

            User.Fullname = textBox1.Text;
            User.Login    = textBox2.Text;
            if (checkBox1.Checked)
            {
                User.Password = Sha1.Encrypt(textBox3.Text);
            }
            User.Group = Groups[comboBox1.SelectedIndex];
            UpdateEventTypeLib(User);
            UpdateStatusLib(User);


            Entity = server.UpdateUser(User);
            base.button1_Click(sender, e);
        }
Example #8
0
        /// <summary>
        ///  获取jssdk签名信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task <WXJsSdkSignatureResp> GetJsSdkSignature(string url)
        {
            if (WXPlatConfigProvider.JsTicketHub == null)
            {
                throw new NullReferenceException("WXPlatConfigProvider 下 JsTicketHub 属性不能为空,因微信访问频率限制,需要通过其设置jsticket统一缓存管理获取。");
            }

            var appConfigRes = await GetMeta();

            if (!appConfigRes.IsSuccess())
            {
                return(new WXJsSdkSignatureResp().WithResp(appConfigRes));
            }

            var appConfig = appConfigRes.data;
            var ticketRes = await WXPlatConfigProvider.JsTicketHub.GetJsTicket(appConfig, WXJsTicketType.jsapi);

            if (!ticketRes.IsSuccess())
            {
                return(new WXJsSdkSignatureResp().WithResp(ticketRes));// ticketRes.ConvertToResultInherit<WXJsSdkSignatureResp>();
            }

            var resp = new WXJsSdkSignatureResp
            {
                app_id    = appConfig.AppId,
                noncestr  = GenerateNonceStr(),
                timestamp = DateTime.Now.ToLocalSeconds()
            };


            var signStr = new StringBuilder();

            signStr.Append("jsapi_ticket=").Append(ticketRes.data);
            signStr.Append("&noncestr=").Append(resp.noncestr);
            signStr.Append("&timestamp=").Append(resp.timestamp);
            if (!string.IsNullOrEmpty(url))
            {
                signStr.Append("&url=").Append(url);
            }

            resp.signature = Sha1.Encrypt(signStr.ToString());

            return(resp);
        }
 private void btnIngresar_Click(object sender, EventArgs e)
 {
     if (txtNombre.Text != "" && txtContraseña.Text != "")
     {
         cnusuario = new CN_Usuario();
         usuario   = cnusuario.accesarLoginC(txtNombre.Text, Sha1.Encrypt(txtContraseña.Text, true));
         Extra.LoginCargar cargarL = new Extra.LoginCargar(usuario);
         cargarL.ShowDialog();
         if (usuario != null)
         {
             Panel_Principal principal = new Panel_Principal(usuario);
             principal.Show();
         }
         else
         {
             txtContraseña.BorderColorFocused = Color.Red;
             txtNombre.BorderColorFocused     = Color.Red;
         }
     }
 }
Example #10
0
 public void Sha1Test()
 {
     string str1 = Sha1.Encrypt("这是一个测试");
 }
Example #11
0
        /// <summary>
        /// 使用sha1方式对字符串进行加密,主要用于对登录密码的再次加密,以防止破解。
        /// 1、在密码后加入SiteOption.SiteHashCode字符串。
        /// 2、使用 sha1 加密。
        /// </summary>
        /// <param name="adminPassword">管理员密码(已经被MD5加密)</param>
        /// <returns></returns>
        public async Task <string> GetAuthenticatePassHash(string adminPassword)
        {
            SiteOptionConfig siteOptionConfig = ConfigHelper.Get <SiteOptionConfig>();

            return(await Task.Run(() => Sha1.Encrypt(adminPassword + siteOptionConfig.SiteHashCode)));
        }
Example #12
0
        //ILog logs = LogManager.GetLogger("Signature");
        //string configPath = ConfigSetting.configPath + "NCD.SNS.Signature.config";

        //public CacheItemRemovedCallback onRemove = null;

        public string Get(string url, string encode)
        {
            string r = "";

            if (encode == "true")
            {
                url = HttpUtility.UrlDecode(url);
            }

            string checkurl = "";// url.Replace("http://", "");


            if (url.IndexOf("http://") != -1)
            {
                checkurl = url.Replace("http://", "");
            }
            else if (url.IndexOf("https://") != -1)
            {
                checkurl = url.Replace("https://", "");
            }


            if (checkurl.IndexOf("/") != -1)
            {
                checkurl = checkurl.Substring(0, checkurl.IndexOf("/"));
            }

            if (url != "")
            {
                if (CheckConfig(checkurl))
                {
                    string ticket    = new JsApiTicket().Get().ticket;
                    string timestamp = Util.GetTimestamp();//Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString();
                    string noncestr  = Util.GetRandomString(36, true, true, true, false, "");
                    string str       = "jsapi_ticket=" + ticket +
                                       "&noncestr=" + noncestr +
                                       "&timestamp=" + timestamp +
                                       "&url=" + url;

                    //logs.Fatal("before signature str:" + str);

                    string signature = Sha1.Encrypt(str);

                    //logs.Fatal("signature:" + signature);

                    SignatureEntity signatureEntity = new SignatureEntity();
                    signatureEntity.appId     = GZH.CL.Config.ConfigSetting.GetWeixin().AppID;
                    signatureEntity.timestamp = timestamp;
                    signatureEntity.nonceStr  = noncestr;
                    signatureEntity.signature = signature.ToLower();
                    signatureEntity.url       = url;

                    //System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer();

                    r = JsonHelper.ScriptSerialize(signatureEntity, false);
                }
                else
                {
                    r = "abort config";
                }
            }
            else
            {
                r = "abort request";
            }

            return(r);
        }
Example #13
0
        public IActionResult TestCommon()
        {
            ViewData["ContentRootPath"] = FileHelper.ContentRootPath;
            ViewData["WebRootPath"]     = FileHelper.WebRootPath;
            ViewData["WebRootName"]     = FileHelper.WebRootName;

            string strRequestMsg = string.Empty;

            strRequestMsg         += " HasFormContentType:" + MyHttpContext.Current.Request.HasFormContentType + Environment.NewLine;
            strRequestMsg         += " Host:" + MyHttpContext.Current.Request.Host + Environment.NewLine;
            strRequestMsg         += " IsHttps:" + MyHttpContext.Current.Request.IsHttps + Environment.NewLine;
            strRequestMsg         += " Method:" + MyHttpContext.Current.Request.Method + Environment.NewLine;
            strRequestMsg         += " Path:" + MyHttpContext.Current.Request.Path + Environment.NewLine;
            strRequestMsg         += " PathBase:" + MyHttpContext.Current.Request.PathBase + Environment.NewLine;
            strRequestMsg         += " Protocol:" + MyHttpContext.Current.Request.Protocol + Environment.NewLine;
            strRequestMsg         += " Scheme:" + MyHttpContext.Current.Request.Scheme + Environment.NewLine;
            ViewData["RequestMsg"] = strRequestMsg;

            ViewData["RequestReferer"] = MyHttpContext.Current.Request.UrlReferrer();
            string strHeaders = string.Empty;

            foreach (String strFormKey in MyHttpContext.Current.Request.Headers.Keys)
            {
                strHeaders += strFormKey + ":" + MyHttpContext.Current.Request.Headers[strFormKey] + "#####";
            }
            ViewData["RequestHeaders"] = strHeaders;

            ViewData["RequestHeadersJSON"] = "";            //MyHttpContext.Current.Request.Headers.ToJson();
            string strForm = string.Empty;

            if (MyHttpContext.Current.Request.Method == "POST")
            {
                foreach (String strFormKey in MyHttpContext.Current.Request.Form.Keys)
                {
                    strForm += strFormKey + ":" + DataConverter.ToString(MyHttpContext.Current.Request.Form[strFormKey]) + "#####";
                }
            }
            ViewData["RequestFormJSON"] = strForm;
            //ViewData["RequestFormJSON"] = MyHttpContext.Current.Request.Form.ToJson();

            string strCurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
            var    resultAdd      = CacheHelper.CacheServiceProvider.AddOrUpdate("CurrentTime", strCurrentTime);

            if (CacheHelper.CacheServiceProvider.Exists("CurrentTime"))
            {
                string resultGet = CacheHelper.CacheServiceProvider.Get <string>("CurrentTime");
                ViewData["CurrentTime"] = resultGet;
            }

            string strMsg        = "我是加密文件,请保管好";
            string strKey        = Guid.NewGuid().ToString().Replace("-", string.Empty);
            string strEncryptAes = AesRijndael.Encrypt(strMsg, strKey);
            string strDecryptAes = AesRijndael.Decrypt(strEncryptAes, strKey);

            ViewData["EncryptAes"] = strEncryptAes;
            ViewData["DecryptAes"] = strDecryptAes;

            string strEncryptHmacSha1       = HmacSha1.EncryptUtf8(strMsg, strKey);
            string strEncryptHmacSha1Base64 = HmacSha1.EncryptBase64(strMsg, strKey);

            ViewData["EncryptHmacSha1"]       = strEncryptHmacSha1;
            ViewData["EncryptHmacSha1Base64"] = strEncryptHmacSha1Base64;

            string strEncryptMd5 = Md5.EncryptHexString(strMsg);

            ViewData["EncryptMd5"] = strEncryptMd5;

            string strEncryptSha1 = Sha1.Encrypt(strMsg);

            ViewData["EncryptSha1"] = strEncryptSha1;

            ViewData["ClientIP"] = IPHelper.GetClientIP();
            ViewData["HostIP"]   = IPHelper.GetHostIP();

            ViewData["RandomFormatedNumeric"] = RandomHelper.GetFormatedNumeric(4, 10);
            ViewData["RandomString"]          = RandomHelper.GetRandString(4);
            ViewData["RandomStringByPattern"] = RandomHelper.GetRandStringByPattern("JX###???***");

            ViewData["StringHelper-GetHashKey"]       = StringHelper.GetHashKey(strMsg, StringFilterOptions.HoldChinese);
            ViewData["StringHelper-GetStringHashKey"] = StringHelper.GetStringHashKey(strMsg);
            ViewData["StringHelper-MD5"]         = StringHelper.MD5(strMsg);
            ViewData["StringHelper-MD5D"]        = StringHelper.MD5D(strMsg);
            ViewData["StringHelper-MD5GB2312"]   = StringHelper.MD5GB2312(strMsg);
            ViewData["StringHelper-SHA1"]        = StringHelper.SHA1(strMsg);
            ViewData["StringHelper-ValidateMD5"] = StringHelper.ValidateMD5(strEncryptMd5, StringHelper.MD5(strMsg));

            ViewData["StringHelper-SubString"]       = StringHelper.SubString(strMsg, 12, "...");
            ViewData["StringHelper-GetInitial"]      = StringHelper.GetInitial(strMsg);
            ViewData["StringHelper-MakeSpellCode"]   = ChineseSpell.MakeSpellCode(strMsg, SpellOptions.EnableUnicodeLetter);
            ViewData["StringHelper-FirstLetterOnly"] = ChineseSpell.MakeSpellCode(strMsg, SpellOptions.FirstLetterOnly);

            ViewData["XmlSerializer"] = ConfigHelper.Get <IPLockConfig>().ToXml();
            var strXML       = "<IPLockConfig> <AdminLockIPBlack>10.123.123.1</AdminLockIPBlack> <AdminLockIPType>30.123.123.3</AdminLockIPType> <AdminLockIPWhite>20.123.123.2</AdminLockIPWhite> <LockIPType>60.123.123.6</LockIPType> <LockIPBlack>40.123.123.4</LockIPBlack> <LockIPWhite>50.123.123.5</LockIPWhite> </IPLockConfig>";
            var ipLockConfig = strXML.ToXmlObject <IPLockConfig>();

            ViewData["XmlDeserialize"] = "IPLockConfig:" + ipLockConfig.AdminLockIPBlack + " " + ipLockConfig.AdminLockIPType + " " + ipLockConfig.AdminLockIPWhite;

            ViewData["JsonSerializer"] = ConfigHelper.Get <WebHostConfig>().ToJson();
            ConfigHelper.Save(ConfigHelper.Get <ShopConfig>());
            ConfigHelper.Save(ConfigHelper.Get <SiteConfig>());
            ConfigHelper.Save(ConfigHelper.Get <SiteOptionConfig>());
            ConfigHelper.Save(ConfigHelper.Get <SmsConfig>());
            ConfigHelper.Save(ConfigHelper.Get <UserConfig>());
            ConfigHelper.Save(ConfigHelper.Get <WebHostConfig>());
            var strJSON    = "{\"AuthenticationType\": 0,\"EnabledSsl\": false,\"MailFrom\": \"[email protected]\",\"MailServer\": \"smtp.qq.com\",\"MailServerPassWord\": \"lx123456\",\"MailServerUserName\": \"2094838895\",\"Port\": \"25\"}";
            var mailConfig = strJSON.ToJsonObject <MailConfig>();

            ViewData["JsonDeserialize"] = mailConfig.AuthenticationType + " " + mailConfig.EnabledSsl + " " + mailConfig.MailFrom + " " + mailConfig.MailServer;


            CookieHelper.CreateCookie("cName", "aspnetcore" + strCurrentTime, 10);
            ViewData["CookieHelper"] = CookieHelper.GetCookie("cName");
            //CookieHelper.DeleteCookie("cName");

            DateTime beginDate = new DateTime(2015, 12, 5);
            DateTime endDate   = DateTime.Now;

            ViewData["DateDiff-yyyy"] = Utility.DateDiff(beginDate, endDate, "yyyy");
            ViewData["DateDiff-q"]    = Utility.DateDiff(beginDate, endDate, "q");
            ViewData["DateDiff-m"]    = Utility.DateDiff(beginDate, endDate, "m");
            ViewData["DateDiff-d"]    = Utility.DateDiff(beginDate, endDate, "d");
            ViewData["DateDiff-w"]    = Utility.DateDiff(beginDate, endDate, "w");
            ViewData["DateDiff-h"]    = Utility.DateDiff(beginDate, endDate, "h");
            ViewData["DateDiff-n"]    = Utility.DateDiff(beginDate, endDate, "n");
            ViewData["DateDiff-s"]    = Utility.DateDiff(beginDate, endDate, "s");

            ViewData["Query-name"]   = Utility.Query("name");
            ViewData["Query-date"]   = Utility.Query("date", DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss:fff");
            ViewData["Query-age"]    = Utility.Query("age", 0);
            ViewData["Query-mobile"] = Utility.AddQuery("mobile", "15871375589");

            var mailConfigSession = ConfigHelper.Get <MailConfig>();

            Utility.SetSession("sessionName", mailConfigSession);

            ViewData["GroupTypeEnum"]  = EnumHelper.GetDescription((GroupTypeEnum)(0));
            ViewData["GroupTypeEnum1"] = EnumHelper.GetDescription <GroupTypeEnum>(GroupTypeEnum.Agent.ToString());

            LogFactory.SaveFileLog("日志标题get", "日志内容");


            return(View());
        }