encrypt and decrypt mailid..

Posted by Gopal_nivas under ASP.NET on 9/15/2010 | Points: 10 | Views : 1865 | Status : [Member] | Replies : 1
hi..


i am doing account confirmation link..
i want to encrypt the mailid.. after that i want to send tat encrypted link to particular mailid..

if tat user clicked tat link means i want to decrypt tat mailid..

i was used a encryption class.. in tat class its encrypt and decrypt normal mailids.. but if i mail id having some special characters it doesnot able to decrypt tat mailid..

i need a encryption and decryption class for all mailids..



this is my class i have used:



using System;

using System.Data;

using System.Configuration;



using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;



using System.Text;

using System.Security.Cryptography;

using System.IO;



namespace QueryStringEncryption
{

public class Cryptography
{

#region Fields



private static byte[] key = { };

private static byte[] IV = { 38, 55, 206, 48, 28, 64, 20, 16 };

private static string stringKey = "!5663a#KN";



#endregion



#region Public Methods



public static string Encrypt(string text)
{

try
{

key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));



DESCryptoServiceProvider des = new DESCryptoServiceProvider();

Byte[] byteArray = Encoding.UTF8.GetBytes(text);



MemoryStream memoryStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(memoryStream,

des.CreateEncryptor(key, IV), CryptoStreamMode.Write);



cryptoStream.Write(byteArray, 0, byteArray.Length);

cryptoStream.FlushFinalBlock();



return Convert.ToBase64String(memoryStream.ToArray());

}

catch (Exception ex)
{

// Handle Exception Here

}



return string.Empty;

}



public static string Decrypt(string text)
{

try
{

key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));



DESCryptoServiceProvider des = new DESCryptoServiceProvider();

Byte[] byteArray = Convert.FromBase64String(text);



MemoryStream memoryStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(memoryStream,

des.CreateDecryptor(key, IV), CryptoStreamMode.Write);



cryptoStream.Write(byteArray, 0, byteArray.Length);

cryptoStream.FlushFinalBlock();



return Encoding.UTF8.GetString(memoryStream.ToArray());

}

catch (Exception ex)
{

// Handle Exception Here

}



return string.Empty;

}



#endregion

}

}
------------------------------

need ur suggestions with example..

regards
gopal.s




Responses

Posted by: T.saravanan on: 9/15/2010 [Member] [MVP] Silver | Points: 25

Login to post response