Decrypting the Encrypted String

Enter the password you used to encrypt the text into the textbox and click the "Decrypt" button. You should see the plain text string you entered in the previous page.


Please enter the password:


Source Code
<script language="c#" runat="server">

  void DecryptText(object sender, EventArgs e)
  {
	// Instantiate our object.  main.rc4encrypt is the namespace
	// name and the class name which gives us a reference to the
	// class.  We use rc4 as the variable name for our object and
	// use the new keyword to create a new instance of the object
	main.rc4encrypt rc4 = new main.rc4encrypt();

	// Set the Password property to the password we want to use
	rc4.Password = txtPassword.Text;

	// Set the PlainText password of the text we want to encrypt
	rc4.PlainText = Request.QueryString["enc"].ToString();

	// Write out to the page the encrypted output
	lblResults.Text = "The Encrypted Text is: " + 
	               Request.QueryString["enc"].ToString() +
	               "<br />The <i>Decrypted</i> Text is: " + 
	               rc4.EnDeCrypt();
  }  

</script>

  <form runat="server">
    Please enter the password:
    <asp:TextBox id="txtPassword" runat="server" />
    <br />
    <asp:Button Text="Decrypt" runat="server" OnClick="DecryptText" />    
    <p>
    <asp:label id="lblResults" runat="server" />
  </form>
 


[Return to the article]