//This class is for decrypt the encrypted value //call this method with two parameters text and key "01AB=$6Q"
class DecryptClass {
public static string Decrypt(string text, string key) {
byte[] encodedkey; byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; byte[] bytes; encodedkey = Encoding.UTF8.GetBytes(key); DESCryptoServiceProvider csp = new DESCryptoServiceProvider(); bytes = Convert.FromBase64String(text);
MemoryStream ms = new MemoryStream(); try { CryptoStream cs = new CryptoStream(ms, csp.CreateDecryptor(encodedkey, iv),CryptoStreamMode.Write); cs.Write(bytes, 0, bytes.Length); cs.FlushFinalBlock(); } catch (Exception ex) { Logger.LogInfo(ex); }
return Encoding.UTF8.GetString(ms.ToArray());
}
}
|
| Author: Amit Srivastava 15 Apr 2009 | Member Level: Bronze Points : 1 |
This code complements the previous encryption code by Shivshankar. All things encrypted, must be decrypted. Here also if some explanation about classes, methods and namespaces is provided i (and other visitors) would have benfitted in a better way by your article sir.
|