.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Encrypt Passing Parameter in Url QueryString

Posted By:Athira Sreejith       Posted Date: December 31, 2008    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

using System;
using System.Data;
using System.Configuration;
using System.Linq;
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.Xml.Linq;
using System.Security.Cryptography;
using System.Xml;
using System.Text;
using System.IO;

public class Encryption
{
private static byte[] keys = { };
private static byte[] IVs = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
private static string EncryptionKeys = "!5623a#de";
public Encryption()
{

}
public static string Decryption(string sInput)
{
Byte[] inputArray = new Byte[sInput.Length];
try
{
keys = System.Text.Encoding.UTF8.GetBytes
(EncryptionKey.Substring(0, 8));
DESCryptoServiceProvider description = new DESCryptoServiceProvider();
inputArray = Convert.FromBase64String(sInput);
MemoryStream mstream = new MemoryStream();
CryptoStream cstream = new CryptoStream
(mstream, description.CreateDecryptor(keys, IVs), 
>CryptoStreamMode.Write);
cstream.Write(inputArray, 0, inputArray.Length);
cstream.FlushFinalBlock();

Encoding encoding = Encoding.UTF8;
return encoding.GetString(mstream .ToArray());

}
catch (Exception ex)
{
return "";
}

}
public static string Encrypt(string sInput)
{
try
{
keys = System.Text.Encoding.UTF8.GetBytes
(EncryptionKey.Substring(0, 8));
DESCryptoServiceProvider description = new DESCryptoServiceProvider();
Byte[] inputArray = Encoding.UTF8.GetBytes(Input);
MemoryStream mstream = new MemoryStream();
CryptoStream cstream = new CryptoStream
(mstream, description.CreateEncryptor(keys, IVs),CryptoStreamMode.Write);
cstream.Write(inputArray, 0, inputArray.Length);
cstream.FlushFinalBlock();
return Convert.ToBase64String(mstream.ToArray());
}
catch (Exception ex)
{
return "";
}


}
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend