Exemplo n.º 1
0
        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <param name="tradeAccount">登陆账号</param>
        /// <param name="tradePwd">登陆密码</param>
        /// <param name="mac">mac地址</param>
        /// <returns>Loginfo</returns>
        public Loginfo GetLogin(string tradeAccount, string tradePwd, string mac)
        {
            //实例化实体类
            Loginfo loginfo = new Loginfo();

            loginfo.LoginID = "-1";
            try
            {
                tradePwd = Des3.Des3EncodeCBC(tradePwd);
                //判断用户是否存在 函数1
                if (ComFunction.ListLogin(ref loginfo, tradeAccount, tradePwd, mac))
                {
                    loginfo.LoginID = System.Guid.NewGuid().ToString().Replace("-", "");

                    //如果存在 随机生存登陆标识 并更新到数据库 查询行情IP和PORT 返回实体类
                    ComFunction.ListLoginfo(ref loginfo, tradeAccount, tradePwd);
                }
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                loginfo.LoginID = "-1";
            }
            return(loginfo);
        }
Exemplo n.º 2
0
    /// <summary>
    /// 类测试
    /// </summary>
    public static void Test()
    {
        System.Text.Encoding utf8 = System.Text.Encoding.UTF8;

        //key为abcdefghijklmnopqrstuvwx的Base64编码
        byte[] key  = Convert.FromBase64String("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4");
        byte[] iv   = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };        //当模式为ECB时,IV无用
        byte[] data = utf8.GetBytes("中国ABCabc123");

        System.Console.WriteLine("ECB模式:");
        byte[] str1 = Des3.Des3EncodeECB(key, iv, data);
        byte[] str2 = Des3.Des3DecodeECB(key, iv, str1);
        System.Console.WriteLine(Convert.ToBase64String(str1));
        System.Console.WriteLine(System.Text.Encoding.UTF8.GetString(str2));

        System.Console.WriteLine();

        System.Console.WriteLine("CBC模式:");
        byte[] str3 = Des3.Des3EncodeCBC(key, iv, data);
        byte[] str4 = Des3.Des3DecodeCBC(key, iv, str3);
        System.Console.WriteLine(Convert.ToBase64String(str3));
        System.Console.WriteLine(utf8.GetString(str4));

        System.Console.WriteLine();
    }
Exemplo n.º 3
0
    public static String GetEncString(String text)
    {
        System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
        byte[] key  = Convert.FromBase64String("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4");
        byte[] iv   = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };        //当模式为ECB时,IV无用
        byte[] data = utf8.GetBytes(text);

        byte[] str3 = Des3.Des3EncodeCBC(key, iv, data);

        String encString = Convert.ToBase64String(str3);

        return(encString);
    }
Exemplo n.º 4
0
        /// <summary>
        /// 测试
        /// </summary>
        public static void Test()
        {
            System.Console.WriteLine("3DES 加密-解密 测试, 测试目标, 明确 ECB 模式  与 CBC 模式 的区别!");


            System.Text.Encoding utf8 = System.Text.Encoding.UTF8;

            // key为abcdefghijklmnopqrstuvwx的Base64编码
            byte[] key = Convert.FromBase64String("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4");

            // 当模式为ECB时,IV无用
            byte[] iv  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            byte[] iv2 = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };


            // 原文.
            byte[] data = utf8.GetBytes("中国ABCabc123");


            System.Console.WriteLine("ECB模式:");

            // 加密
            byte[] str1 = Des3.Des3EncodeECB(key, iv, data);
            System.Console.WriteLine("加密结果:{0}", Convert.ToBase64String(str1));

            // 验证,是否 ECB 模式下, IV 无用.
            byte[] strECB = Des3.Des3EncodeECB(key, iv2, data);
            System.Console.WriteLine("设置了其他的IV,加密结果为:{0}", Convert.ToBase64String(strECB));

            // 解密.
            byte[] str2 = Des3.Des3DecodeECB(key, iv, str1);
            System.Console.WriteLine("解密后结果:{0}", System.Text.Encoding.UTF8.GetString(str2));
            System.Console.WriteLine();



            System.Console.WriteLine("CBC模式:");

            // 加密
            byte[] str3 = Des3.Des3EncodeCBC(key, iv, data);
            System.Console.WriteLine("加密结果:{0}", Convert.ToBase64String(str3));

            // 验证,是否 CBC 模式下, IV 是有用的.
            byte[] strCBC = Des3.Des3EncodeCBC(key, iv2, data);
            System.Console.WriteLine("设置了其他的IV,加密结果为:{0}", Convert.ToBase64String(strCBC));

            // 解密.
            byte[] str4 = Des3.Des3DecodeCBC(key, iv, str3);
            System.Console.WriteLine("解密后结果:{0}", utf8.GetString(str4));
            System.Console.WriteLine();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 行情客户端用户登陆
        /// </summary>
        /// <param name="tradeAccount">登陆账号</param>
        /// <param name="tradePwd">登陆密码</param>
        /// <param name="mac">mac地址</param>
        /// <returns>Loginfo</returns>
        public Loginfo GetLoginEx(string tradeAccount, string tradePwd, string mac)
        {
            //实例化实体类
            Loginfo loginfo = new Loginfo();

            loginfo.LoginID = "-1";
            try
            {
                tradePwd = Des3.Des3EncodeCBC(tradePwd);
                //判断用户是否存在 函数1
                if (ComFunction.ListLogin(ref loginfo, tradeAccount, tradePwd, mac))
                {
                    loginfo.LoginID         = System.Guid.NewGuid().ToString().Replace("-", "");
                    loginfo.QuotesAddressIP = ComFunction.ip;
                    loginfo.QuotesPort      = Convert.ToInt32(ComFunction.port);
                }
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                loginfo.LoginID = "-1";
            }
            return(loginfo);
        }
Exemplo n.º 6
0
    /// <summary>
    /// 类测试
    /// </summary>
    public static void Test()
    {
        System.Text.Encoding utf8 = System.Text.Encoding.UTF8;

        //key为abcdefghijklmnopqrstuvwx的Base64编码
        string ydata = "00068900002||20180927095839|||3002800173|0200000777|01|0155129175|||";

        byte[] key = Convert.FromBase64String("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4");
        byte[] iv  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };     //当模式为ECB时,IV无用

        byte[] data = utf8.GetBytes(ydata);
        System.Console.WriteLine("原始报文:");
        System.Console.WriteLine(ydata);
        System.Console.WriteLine();

        byte[] str1 = Des3.Des3EncodeECB(key, iv, data);
        byte[] str2 = Des3.Des3DecodeECB(key, iv, str1);
        System.Console.WriteLine("ECB加密报文:");
        System.Console.WriteLine(Convert.ToBase64String(str1));
        System.Console.WriteLine("ECB解密报文:");
        System.Console.WriteLine(System.Text.Encoding.UTF8.GetString(str2));

        System.Console.WriteLine();


        byte[] str3 = Des3.Des3EncodeCBC(key, iv, data);
        byte[] str4 = Des3.Des3DecodeCBC(key, iv, str3);
        System.Console.WriteLine("CBC加密报文:");
        System.Console.WriteLine(Convert.ToBase64String(str3));
        System.Console.WriteLine("CBC解密报文:");
        System.Console.WriteLine(utf8.GetString(str4));

        System.Console.WriteLine();

        Console.ReadLine();
    }
Exemplo n.º 7
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="LoginID">用户登陆标识ID</param>
        /// <param name="PwdType">0表示修改登陆密码,1表示修改资金密码</param>
        /// <param name="oldpwd">旧密码</param>
        /// <param name="newpwd">新密码</param>
        /// <returns></returns>
        public ResultDesc ModifyUserPassword(string LoginID, int PwdType, string oldpwd, string newpwd)
        {
            ResultDesc rsdc = new ResultDesc();

            try
            {
                TradeUser tdUser = new TradeUser();

                List <string> sqlList = new List <string>();


                if (!ComFunction.ExistUserLoginID(LoginID, ref tdUser))
                {
                    rsdc.Result     = false;
                    rsdc.ReturnCode = ResCode.UL003;
                    rsdc.Desc       = ResCode.UL003Desc;
                    return(rsdc);
                }
                //密码转换
                oldpwd = Des3.Des3EncodeCBC(oldpwd);
                newpwd = Des3.Des3EncodeCBC(newpwd);

                string sql1 = string.Empty;
                if (PwdType == 0)//登陆密码
                {
                    if (tdUser.LoginPwd == oldpwd)
                    {
                        sql1 = string.Format("UPDATE Base_User  SET  LoginPwd='{0}'  WHERE userid='{1}' AND LoginPwd='{2}'", newpwd, tdUser.UserID, oldpwd);
                        sqlList.Add(sql1);
                    }
                    else
                    {
                        rsdc.Result = false;
                        rsdc.Desc   = "登陆密码不一致,修改失败";
                        return(rsdc);
                    }
                }
                else//资金密码
                {
                    if (tdUser.CashPwd == oldpwd)
                    {
                        sql1 = string.Format("UPDATE Base_User  SET  CashPwd='{0}'  WHERE userid='{1}' AND CashPwd='{2}'", newpwd, tdUser.UserID, oldpwd);
                        sqlList.Add(sql1);
                    }
                    else
                    {
                        rsdc.Result = false;
                        rsdc.Desc   = "资金密码不一致,修改失败";
                        return(rsdc);
                    }
                }
                if (!ComFunction.SqlTransaction(sqlList))
                {
                    LogNet4.WriteMsg(string.Format("修改密码失败,SQL语句执行失败,SQL语句是:{0}", sql1));
                    rsdc.Result = false;
                    rsdc.Desc   = "用户密码不对,修改密码失败";
                    return(rsdc);
                }
                rsdc.Result = true;
                rsdc.Desc   = "修改密码,成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc   = "修改密码,失败";
            }
            return(rsdc);
        }