⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.aspx.cs

📁 JAVA实现的RSA公钥加密方法
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DJD.Security;

namespace SecurityWebApp
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class Login : System.Web.UI.Page
	{
		protected HtmlInputHidden eInput;
		protected HtmlInputHidden nInput;
		protected HtmlInputHidden textInput;
		protected System.Web.UI.WebControls.TextBox txtUID;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.DropDownList cboDomains;
		protected System.Web.UI.WebControls.Label lblError;
		protected Button loginButton;

		private void Page_Load(object sender, System.EventArgs e)
		{
			DJD.Security.Encryption sec = new Encryption(256);
			if (!IsClientScriptBlockRegistered("script") )
			{
				string str = sec.GetJavaScriptClientCode();
				RegisterClientScriptBlock("script",str);
			}
				
			if (Session["d"] == null) 
			{
				Session["d"] = sec.ExportParamaters(true).D.ToString(16);
				Session["e"] = sec.ExportParamaters(true).E.ToString(16);
				Session["n"] = sec.ExportParamaters(true).N.ToString(16);
			}
			
			if (Page.IsPostBack) 
			{
				lblError.Text = "";
				string c = Request.Form["password"];
				BigInteger bi_d = new BigInteger(Convert.ToString(Session["d"]), 16);
				BigInteger bi_n = new BigInteger(Convert.ToString(Session["n"]), 16);

				BigInteger bi_encrypted = new BigInteger(c,16);
				BigInteger bi_decrypted = bi_encrypted.modPow(bi_d,bi_n);

				string strDecPassword = bi_decrypted.ToString(95);

				// now you have the decrypted password that the user entered...
				// do some kind of authentication now (you can replace the ActiveDirectory authentication
				// with your own.

                DJD.Security.Authentication oAuth = new DJD.Security.Authentication();
				string strReturn = oAuth.Authenticate(System.Environment.UserDomainName, txtUID.Text,strDecPassword);
			
				if (strReturn == "True") 
				{
					lblError.Text += " ...You're authenticated";
					// get rid of the keys, so the session state is smaller.
					Session.Remove("d");
					Session.Remove("e");
					Session.Remove("n");
				}
				else
				{
					lblError.Text += "... NOPE: " + strReturn;
				}
				lblError.Text += "<BR>Decrypted password is " + strDecPassword;
				lblError.Text += "<BR>USER: " + System.Environment.UserDomainName + "\\" + txtUID.Text;
			}






			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -