Beispiel #1
0
        private void btn_get_Click(object sender, EventArgs e)
        {
            string timespan = ParasAuthentication.ToUnixTime(DateTime.Now).ToString();


            Dictionary <string, string> data = new Dictionary <string, string>
            {
                {
                    "UserName",
                    tb_Name.Text
                },
                {
                    "SecurePassword",
                    DesHelper.DES3Encrypt(tb_pwd.Text, "")
                }
            };
            string body = JsonConvert.SerializeObject(data);

            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                {
                    "[Body]",
                    body
                },
                {
                    "Timespan",
                    timespan
                }
            };
            string sign = ParasAuthentication.CreateSign(parameters, this.SecurityValue);

            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                {
                    "AppVersion",
                    "1.0.0.10"
                },
                {
                    "Signature",
                    sign
                },
                {
                    "Timespan",
                    timespan
                }
            };

            string resultStr = HttpHelper.HttpPost(string.Format("{0}/login/", this.BaseUrl), body
                                                   , headers);

            tb_token.Text = resultStr;
        }
Beispiel #2
0
        /// <summary>
        /// 使用3DES加密保存文件数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="path">文件</param>
        /// <param name="key">密钥</param>
        /// <typeparam name="T">数据类型</typeparam>
        public static void SaveDataWithDes3 <T>(T data, string path, string key = "")
        {
            bool flag = string.IsNullOrEmpty(key);

            if (flag)
            {
                key = DesHelper.Des3Key;
            }
            string contents = JsonConvert.SerializeObject(data);
            string des3Data = DesHelper.DES3Encrypt(contents, key);

            File.WriteAllText(path, des3Data, Encoding.UTF8);
        }
Beispiel #3
0
        /// <summary>
        /// 解密获取使用3DES加密的文件数据
        /// </summary>
        /// <param name="path">加密文件</param>
        /// <param name="key">密钥</param>
        /// <typeparam name="T">数据类型</typeparam>
        /// <returns>解密数据</returns>
        public static T GetDataWithDes3 <T>(string path, string key = "")
        {
            bool flag = !File.Exists(path);
            T    result2;

            if (flag)
            {
                result2 = default(T);
            }
            else
            {
                bool flag2 = string.IsNullOrEmpty(key);
                if (flag2)
                {
                    key = DesHelper.Des3Key;
                }
                string des3Data = File.ReadAllText(path, Encoding.UTF8);
                string data     = DesHelper.DES3Decrypt(des3Data, key);
                T      result   = JsonConvert.DeserializeObject <T>(data);
                result2 = result;
            }
            return(result2);
        }