Encryption and Decryption in ASP.NET with C#.Net(1024 -bit Encryption and Decryption)


In most of the application we need to give security to the password, URL(security query strings) and more.  For this purpose microsoft has provided<b><span style="color: #274e13;">&nbsp;System.Security.Cryptography.  In the below example i have encrypted "Ranga Rajesh Kumar" with 1024-bit encryption algorithm.  when ever we required we will use 1024 bit decryption key for getting original string. Example: >using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Security.Cryptography; namespace EncriptDecript { class Program { static void Main(string[] args) { string strText = EncryptIt("Ranga Rajesh Kumar"); Console.WriteLine("Encrypted text:" + strText); strText = DecryptIt(strText); Console.WriteLine("Decrypted text:" + strText); Console.ReadLine(); } public static string EncryptIt(string encryptData) { try { byte[] data = ASCIIEncoding.ASCII.GetBytes(encryptData); byte[] rgbKey = ASCIIEncoding.ASCII.GetBytes("12345678"); byte[] rgbIV = ASCIIEncoding.ASCII.GetBytes("87654321"); //1024-bit encryption MemoryStream memoryStream = new MemoryStream(1024); DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider(); CryptoStream cryptoStream = new CryptoStream(memoryStream, desCryptoServiceProvider.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write); cryptoStream.Write(data, 0, data.Length); cryptoStream.FlushFinalBlock(); byte[] result = new byte[(int)memoryStream.Position]; memoryStream.Position = 0…

View original post 89 more words


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s