Ejemplo n.º 1
0
        public JsonResult Login(string login_info, string app_id)
        {
            LogHelper.WriteLog(jCodesenum.LogLevel.LOG_LEVEL_DEBUG, "输入参数 [login_info: " + login_info + ", app_id: " + app_id + "]", typeof(InterfaceController));
            // TODO 查询数据库 appid
            AppConfig config = new AppConfig();

            string privateKey     = config.AppConfigGet("WX_PrivateKey").Replace("&lt;", "<").Replace("&gt;", ">");
            var    rsa            = new RSA(privateKey);
            string str_login_info = rsa.DecodeOrNull(login_info);

            LogHelper.WriteLog(jCodesenum.LogLevel.LOG_LEVEL_DEBUG, "输出参数 [str_login_info: " + str_login_info + "]:", typeof(InterfaceController));

            return(Json(new { errCode = 0, errMsg = str_login_info }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        private void btnRSATOJAVA_Click(object sender, EventArgs e)
        {
            Console.WriteLine("---------------------------------------------------------");
            Console.WriteLine("◆◆◆◆◆◆◆◆◆◆◆◆ RSA测试 ◆◆◆◆◆◆◆◆◆◆◆◆");
            Console.WriteLine("---------------------------------------------------------");

            var rsa = new RSA(512);

            Console.WriteLine("【512私钥(XML)】:");
            Console.WriteLine(rsa.ToXML());
            Console.WriteLine();
            Console.WriteLine("【512私钥(PEM)】:");
            Console.WriteLine(rsa.ToPEM_PKCS1());
            Console.WriteLine();
            Console.WriteLine("【512公钥(PEM)】:");
            Console.WriteLine(rsa.ToPEM_PKCS1(true));
            Console.WriteLine();

            var str = "abc内容123";
            var en  = rsa.Encode(str);

            Console.WriteLine("【加密】:");
            Console.WriteLine(en);

            Console.WriteLine("【解密】:");
            Console.WriteLine(rsa.DecodeOrNull(en));

            Console.WriteLine("【签名SHA1】:");
            Console.WriteLine(rsa.Sign("SHA1", str));
            Console.WriteLine();

            var rsa2 = new RSA(rsa.ToPEM_PKCS8(), true);

            Console.WriteLine("【用PEM新创建的RSA是否和上面的一致】:");
            Console.WriteLine("XML:" + (rsa2.ToXML() == rsa.ToXML()));
            Console.WriteLine("PKCS1:" + (rsa2.ToPEM_PKCS1() == rsa.ToPEM_PKCS1()));
            Console.WriteLine("PKCS8:" + (rsa2.ToPEM_PKCS8() == rsa.ToPEM_PKCS8()));

            var rsa3 = new RSA(rsa.ToXML());

            Console.WriteLine("【用XML新创建的RSA是否和上面的一致】:");
            Console.WriteLine("XML:" + (rsa3.ToXML() == rsa.ToXML()));
            Console.WriteLine("PKCS1:" + (rsa3.ToPEM_PKCS1() == rsa.ToPEM_PKCS1()));
            Console.WriteLine("PKCS8:" + (rsa3.ToPEM_PKCS8() == rsa.ToPEM_PKCS8()));

            Console.WriteLine("-------------------------------------------------------------");
            Console.WriteLine("◆◆◆◆◆◆◆◆◆◆◆◆ 回车退出... ◆◆◆◆◆◆◆◆◆◆◆◆");
            Console.WriteLine();
        }