Click here to Skip to main content
15,914,221 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">

    <div>

        Input : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <asp:Button ID="Button1" runat="server" Text="encrypt"

            onclick="Button1_Click" />

        <br /><br />

        Output : <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

        <asp:Button ID="Button2" runat="server" Text="decrypt"

            onclick="Button2_Click" />

            <br /><br />

            Final Result :

        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

    </div>

    </form>
</body>
</html>

c#

C#
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.Security;



public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {



    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        TextBox2.Text = Encrypt(TextBox1.Text.Trim());

    }

    public static string Encrypt(string strPassword)
    {

        FormsAuthenticationTicket Ftk = new FormsAuthenticationTicket(strPassword, false, 1);

        return FormsAuthentication.Encrypt(Ftk);

    }



    public static string Decrypt(string encryptedString)
    {

        FormsAuthenticationTicket Ftk = FormsAuthentication.Decrypt(encryptedString);

        return Ftk.Name;

    }

    protected void Button2_Click(object sender, EventArgs e)
    {

        Label1.Text = Decrypt(TextBox2.Text.Trim());

    }

}
Posted
Comments
_Amy 24-Sep-12 6:14am    
Did you forgot to ask your question?
StianSandberg 24-Sep-12 6:14am    
and your question?
CPallini 24-Sep-12 6:16am    
And the question is?!

1 solution

Please next time if we see half question then it will be consider spam and no response to it will be given , and yes what u writing in there is complete crab , user the below code

create a seprate class for it

C#
using System.Collections.Generic;
using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;


C#
private static Byte[] sharedkey = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
        private static Byte[] sharedvector = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };



public static string Encrypt(string val)
       {
           TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
           Byte[] toEncrypt = Encoding.UTF8.GetBytes(val);
           MemoryStream ms = new MemoryStream();
           CryptoStream cs = new CryptoStream(ms, tdes.CreateEncryptor(sharedkey, sharedvector), CryptoStreamMode.Write);
           cs.Write(toEncrypt, 0, toEncrypt.Length);
           cs.FlushFinalBlock();
           return Convert.ToBase64String(ms.ToArray());
       }



public static string Decrypt(string val)
      {
          TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
          Byte[] toDecrypt = Convert.FromBase64String(val);
          MemoryStream ms = new MemoryStream();
          CryptoStream cs = new CryptoStream(ms, tdes.CreateDecryptor(sharedkey, sharedvector), CryptoStreamMode.Write);
          cs.Write(toDecrypt, 0, toDecrypt.Length);
          cs.FlushFinalBlock();
          return Encoding.UTF8.GetString(ms.ToArray());
      }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900