Encoding a Plain Text String

This demo illustrates how to encrypt a plain text string using the rc4encrypt class. Once you have encrypted a string, click the provided link to decrypt the string.

Choose a Password:
Enter the Text to be Encrypted:

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

  void EncryptText(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 = txtEncrypt.Text;

	// Write out to the page the encrypted output
	lblResults.Text = "The Encrypted Text is:<br />" + rc4.EnDeCrypt();
	// Create the hyperlink to decrypt the string
	lnkDecrypt.Text="Decrypt the String";
	lnkDecrypt.NavigateUrl = "/demos/rc4decrypt.aspx?enc=" +


  <form runat="server">
    Choose a Password:
    <asp:textbox id="txtPassword" runat="server" />
    <br />
    Enter the Text to be Encrypted:
    <asp:textbox id="txtEncrypt" runat="server" Columns="45" MaxLength="50" />
    <br />
    <asp:Button runat="server" OnClick="EncryptText" Text="Encrypt!" />
    <asp:label id="lblResults" runat="server" /><br />
    <asp:hyperlink id="lnkDecrypt" runat="server" />

[Return to the article]