Exemplo n.º 1
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReg_Click(object sender, EventArgs e)
        {
            AppConfig config = Cache.Instance["AppConfig"] as AppConfig;

            if (config == null)
            {
                config = new AppConfig();
                Cache.Instance["AppConfig"] = config;
            }
            string LicensePath = config.AppConfigGet("LicensePath");
            string machineCode = GetMachineCode();
            string regCode     = txtRegisterCode.Text.Trim();
            string userName    = txtUserName.Text.Trim();
            string company     = txtCompany.Text.Trim();
            Int32  passed      = -1;

            passed = RSASecurityHelper.CheckRegistrationCode(regCode, userName, company);

            if (passed == 0)
            {
                MessageDxUtil.ShowTips("祝贺您,注册成功\r\n请重启登录之后才会生效!");
            }
            else
            {
                MessageDxUtil.ShowError("注册失败");
            }
        }
Exemplo n.º 2
0
        //验证
        private void btnValidateCode_Click(object sender, EventArgs e)
        {
            AppConfig config = Cache.Instance["AppConfig"] as AppConfig;

            if (config == null)
            {
                config = new AppConfig();
                Cache.Instance["AppConfig"] = config;
            }
            string LicensePath = config.AppConfigGet("LicensePath");
            string machineCode = GetMachineCode();
            string regCode     = txtRegisterCode.Text.Trim();//FileUtil.FileToString(LicensePath);
            string userName    = txtUserName.Text.Trim();
            string company     = txtCompany.Text.Trim();
            Int32  passed      = -1;

            passed = RSASecurityHelper.CheckRegistrationCode(regCode, userName, company);

            if (passed == 0)
            {
                MessageDxUtil.ShowTips("验证成功");
            }
            else
            {
                MessageDxUtil.ShowTips("验证不成功");
            }
        }
Exemplo n.º 3
0
        private void btRegister_Click(object sender, EventArgs e)
        {
            string regCode  = txtSerialNumber.Text.Trim();
            string userName = txtUserName.Text.Trim();
            string company  = txtCompany.Text.Trim();

            // 校验文本框信息是否完整
            if (!CheckInput())
            {
                return;
            }

            Int32 passed = -1;

            passed = RSASecurityHelper.CheckRegistrationCode(regCode, userName, company);

            if (passed == 0)
            {
                MessageDxUtil.ShowTips("祝贺您,注册成功\r\n请重启登录之后才会生效!");
            }
            else
            {
                MessageDxUtil.ShowError("注册失败");
            }
        }
Exemplo n.º 4
0
        //加密
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }

            string userName    = txtUserName.Text;
            string companyName = txtCompany.Text;

            this.txtRegisterCode.Text = RSASecurityHelper.GetRegistrationCode(userName, companyName);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, System.EventArgs e)
        {
            AppConfig config = new AppConfig();

            /*RSASecurityHelper.GenerateRSAKey(out _privateKey,out _publicKey);
             * string abc = textBox4.Text.Trim();
             * textBox4.Text = RSASecurityHelper.RSAEncrypt(_publicKey, abc);*/
            string piKey = config.AppConfigGet("WX_PrivateKey").Replace("&lt;", "<").Replace("&gt;", ">");
            string puey  = config.AppConfigGet("WX_PublicKey").Replace("&lt;", "<").Replace("&gt;", ">");

            string privateStr = RSASecurityHelper.RSAEncrypt(puey, "吴建明");
            string publicStr  = RSASecurityHelper.RSADecrypt(piKey, privateStr);

            Console.WriteLine(publicStr);


            string decryptStr = "xHYQsXsYuWWyzIJkiLBvcBJCS+EwohLnwsn0cRWMLaKsL4On+l7O/owGt7YiGDUp/sUerqO39b1cHgr+1lBiBeONd8YPMjAgYPCrW7ecr67tReyTwRraIFLp/5dJomQxc9EFPsBQ5au3wXLLH5dYZFXF7ZXqOtdkNFtYi1y/pAM=";
        }
        /// <summary>
        /// 调用非对称加密方式对序列号进行验证
        /// </summary>
        /// <param name="serialNumber">正确的序列号</param>
        /// <returns>如果成功返回True,否则为False</returns>
        public bool Register(String serialNumber)
        {
            string hardNumber = HardwareInfoHelper.GetCPUId();

            return(RSASecurityHelper.Validate(hardNumber, serialNumber));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 每次程序运行时候,检查用户是否注册(如果第一次, 那么写入第一次运行时间)
        /// </summary>
        /// <returns>如果用户已经注册, 那么返回True, 否则为False</returns>
        public static bool CheckRegister()
        {
            // 保存注册码的信息
            string regCode  = string.Empty;             //注册码
            string userName = string.Empty;             // 注册用户
            string company  = string.Empty;             // 注册公司

            RegistryKey reg = Registry.CurrentUser.OpenSubKey(UIConstants.SoftwareRegistryKey, true);

            // 首先判断注册表中是否存在regCode 注册码的信息,如果没有在从lic文件中读取文件,如果2个都不存在则验证不通过
            if (null == reg)
            {
                AppConfig config = Cache.Instance["AppConfig"] as AppConfig;
                if (config == null)
                {
                    config = new AppConfig();
                    Cache.Instance["AppConfig"] = config;
                }
                string LicensePath = config.AppConfigGet("LicensePath");
                if (FileUtil.IsExistFile(LicensePath))
                {
                    string[] tmpstr = FileUtil.FileToString(LicensePath).Split(Convert.ToChar(Const.VerticalLine));

                    if (tmpstr.Length == 3)
                    {
                        regCode  = tmpstr[0];
                        userName = tmpstr[1];
                        company  = tmpstr[2];
                    }
                }
            }

            // 20170815 wujianming 修复新部署环境报错 未引用实例对象问题
            if (null != reg && reg.GetValue("regCode") != null)
            {
                // 获取验证码
                regCode  = reg.GetValue("regCode").ToString();
                userName = reg.GetValue("UserName").ToString();
                company  = reg.GetValue("Company").ToString();
            }

            // 再去配置表的数据
            if (string.Equals(regCode, string.Empty))
            {
                AppConfig config = Cache.Instance["AppConfig"] as AppConfig;
                if (config == null)
                {
                    config = new AppConfig();
                    Cache.Instance["AppConfig"] = config;
                }

                string LicensePath = config.AppConfigGet("LicensePath");
                if (FileUtil.IsExistFile(LicensePath))
                {
                    string[] tmpstr = FileUtil.FileToString(LicensePath).Split(Convert.ToChar(Const.VerticalLine));

                    if (tmpstr.Length == 3)
                    {
                        regCode  = tmpstr[0];
                        userName = tmpstr[1];
                        company  = tmpstr[2];
                    }
                }
            }

            // 2个都没有获取到注册码信息则认为没有注册过
            if (string.Equals(regCode, string.Empty))
            {
                return(false);
            }
            Int32 passed = RSASecurityHelper.CheckRegistrationCode(regCode, userName, company);

            if (passed == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, System.EventArgs e)
        {
            string abc = textBox4.Text.Trim();

            textBox4.Text = RSASecurityHelper.RSADecrypt(_privateKey, abc);
        }
Exemplo n.º 9
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string original = "测试加密字符串";

            Console.WriteLine("original:" + original);

            string encrypt = EncodeHelper.SHA256(original);

            Console.WriteLine("EncodeHelper.SHA256:" + encrypt);

            //DES加解密
            encrypt = EncodeHelper.DesEncrypt(original);
            Console.WriteLine("EncodeHelper.DesEncrypt:" + encrypt);

            string decrypt = EncodeHelper.DesDecrypt(encrypt);

            Console.WriteLine("EncodeHelper.DesDecrypt:" + decrypt);

            //MD5加密
            encrypt = EncodeHelper.MD5Encrypt(original);
            Console.WriteLine("EncodeHelper.MD5Encrypt:" + encrypt);
            encrypt = EncodeHelper.MD5EncryptHash(original);
            Console.WriteLine("EncodeHelper.MD5EncryptHash:" + encrypt);
            encrypt = EncodeHelper.MD5EncryptHashHex(original);
            Console.WriteLine("EncodeHelper.MD5EncryptHashHex:" + encrypt);
            encrypt = EncodeHelper.EncyptMD5_3_16(original);
            Console.WriteLine("EncodeHelper.EncyptMD5_3_16:" + encrypt);

            //Base64加解密
            encrypt = EncodeHelper.Base64Encrypt(original);
            Console.WriteLine("EncodeHelper.Base64Encrypt:" + encrypt);
            decrypt = EncodeHelper.Base64Decrypt(encrypt);
            Console.WriteLine("EncodeHelper.Base64Encrypt:" + decrypt);

            encrypt = EncodeHelper.AES_Encrypt(original);
            Console.WriteLine("EncodeHelper.AES_Encrypt:" + encrypt);
            decrypt = EncodeHelper.AES_Decrypt(encrypt);
            Console.WriteLine("EncodeHelper.AES_Decrypt:" + decrypt);

            //MD5加密字符串然后检查是否被篡改
            encrypt = MD5Util.GetMD5_32(original);
            bool flag = MD5Util.ValidateValue(encrypt);

            Console.WriteLine("flag: " + flag);

            //为文件增加MD5编码标签,然后验证是否被修改
            string file  = @"DB\test1.xls";
            bool   flag2 = MD5Util.AddMD5(file);

            Console.WriteLine("flag2: " + flag2);

            //对给定路径的文件进行验证,如果一致返回True,否则返回False
            bool flag3 = MD5Util.CheckMD5(file);

            Console.WriteLine("flag3: " + flag3);

            //生成加解密私钥、公钥
            string publicKey  = "";
            string privateKey = "";

            RSASecurityHelper.GenerateRSAKey(out privateKey, out publicKey);

            string originalString  = "testdata";
            string encryptedString = RSASecurityHelper.RSAEncrypt(publicKey, originalString);
            string originalString2 = RSASecurityHelper.RSADecrypt(privateKey, encryptedString);

            if (originalString == originalString2)
            {
                MessageDxUtil.ShowTips("解密完全正确");
            }
            else
            {
                MessageDxUtil.ShowWarning("解密失败");
            }

            string regcode   = RSASecurityHelper.RSAEncrypSignature(privateKey, originalString);
            bool   validated = RSASecurityHelper.Validate(originalString, regcode, publicKey);

            MessageDxUtil.ShowTips(validated ? "验证成功" : "验证失败");
        }