| Author: Ravi 04 Nov 2009 | Member Level: Silver | Rating:  Points: 2 |
Hello,
Please find below the methods for encrypt and decrypt. using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Security.Cryptography; using System.Text; using System.IO;
namespace SQLDAL { /// <summary> /// Summary description for Security. /// </summary> public class Security { public Security() { // // TODO: Add constructor logic here // }
public static string EncryptText(string strText) { return Encrypt(strText, "TwasBrilligsjdhdtEgfbVog9vesHadTeaWithAMadHatter"); }
public static string DecryptText(string strText) { return Decrypt(strText, "TwasBrilligsjdhdtEgfbVog9vesHadTeaWithAMadHatter"); }
private static string Encrypt(string strText, string strEncrKey) { byte[] byKey; byte[] IV = {0, 52, 86, 120, 144, 171, 205, 239}; try { byKey = System.Text.Encoding.UTF8.GetBytes((strEncrKey.Substring(1, 8))); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); byte[] inputByteArray = Encoding.UTF8.GetBytes(strText); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); return Convert.ToBase64String(ms.ToArray()); } catch (Exception ex) { return ex.Message; } }
private static string Decrypt(string strText, string sDecrKey) { byte[] byKey; byte[] IV = {0, 52, 86, 120, 144, 171, 205, 239}; byte[] inputByteArray = new byte[strText.Length]; try { byKey = System.Text.Encoding.UTF8.GetBytes( (sDecrKey.Substring(1, 8))); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); inputByteArray = Convert.FromBase64String(strText); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); System.Text.Encoding encoding = System.Text.ASCIIEncoding.UTF8; return encoding.GetString(ms.ToArray()); } catch (Exception ex) { return ex.Message; } }
} }
Regards, Ravi
|
| Author: Anil Kumar Pandey 04 Nov 2009 | Member Level: Diamond | Rating:  Points: 2 |
check this code for the same..
http://mannpandey.blogspot.com/2009/07/code-encryption-and-decryption-using.html
Thanks & Regards Anil Kumar Pandey
|
| Author: Deepika Haridas 04 Nov 2009 | Member Level: Diamond | Rating:  Points: 2 |
Hello,
You can check resources section for this.
Thanks & Regards, Deepika Editor
If U want to shine like a SUN..First U have to burn like the SUN!! Need a Guide? Join my mentor program..
|
| Author: Nikhil Gaur 04 Nov 2009 | Member Level: Diamond | Rating:  Points: 2 |
look at the following links
http://niksgaur.blogspot.com/2009/07/code-encryption-and-decryption-using.html
http://niksgaur.blogspot.com/2009/08/encryption-and-decryption-without-net.html
Join this campus group http://www.dotnetspider.com/sites/637/-ecb-aspdotnet.aspx
Thanks & Regards NIks My Software and Web Development Experience
|