using System.Security.Cryptography;
public static string EncryptionKey = "ibvrbank1986";
private static byte[] ConvertHexStringToBytes(string hexString)
int numBytes = hexString.Length / 2;
byte[] arrByte = new byte[numBytes];
for (int i = 0; i < numBytes; ++i)
arrByte[i] = byte.Parse(hexString.Substring(i * 2, 2),
System.Globalization.NumberStyles.HexNumber);
private static string ConvertBytesToHexString(byte[] data)
hexString += String.Format("{0:X2}", b);
public static string Decrypt(string stringToDecrypt, string sEncryptionKey)
byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 };
byte[] inputByteArray = new byte[stringToDecrypt.Length];
key = Encoding.GetEncoding("utf-8").GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = ConvertHexStringToBytes(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
Encoding encoding = Encoding.GetEncoding("utf-8");
return encoding.GetString(ms.ToArray());
catch (System.Exception ex)
public static string Encrypt(string stringToEncrypt, string sEncryptionKey)
byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 };
key = Encoding.GetEncoding("utf-8").GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Encoding.GetEncoding("utf-8").GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
return ConvertBytesToHexString(ms.ToArray());
catch (System.Exception ex)
public static void Main()
Console.WriteLine(string.Format("args1 : {0}",Decrypt("DF876004139425A6FCF48B31059F5CD467053098FA3C2D2910DB6A230B6E0DF1A88DBEBD5717172993A3029843067617", EncryptionKey)));
Console.WriteLine(string.Format("{0}",Encrypt("accinfo&type=loan&accnumber=103810005668888", EncryptionKey)));