using System.Security.Cryptography;
public class TripleDESTest
public static void Main()
string pwd = string.Empty;
MD5 md5 = System.Security.Cryptography.MD5.Create();
TripleDES tdes = System.Security.Cryptography.TripleDES.Create();
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.Zeros;
byte[] key = convertKeyToByteArray("346176316e672066756e206e30773f21", 24, md5);
enc = tdes.CreateDecryptor(key, null);
byte[] encrypted = Convert.FromBase64String("cjVpc2crbXJtVTB4RkZMdnRpMmJxQU15Z2JPY1hhYnM=");
byte []tmp = enc.TransformFinalBlock(encrypted, 0, encrypted.Length);
protected static byte toByte( char ch)
System.Text.Encoding enc = System.Text.Encoding.GetEncoding( "utf-8");
byte[] b = enc.GetBytes( new char[] {ch});
if (b != null && b.Length > 0)
protected static string toString( byte[] inp)
UTF8Encoding utf8 = new UTF8Encoding();
return utf8.GetString( inp);
protected static byte[] toByteArray( string inp)
UTF8Encoding utf8 = new UTF8Encoding();
return utf8.GetBytes( inp);
protected static byte[] convertKeyToByteArray( string key, int size, MD5 md5 )
byte[] newIVKey = new byte[ivSize];
md5buffer = md5.ComputeHash( toByteArray(key) );
string md5string = string.Empty;
foreach (byte bte in md5buffer)
md5string += string.Format( "{0:x02}", bte);
for (int i = 0; i < ivSize; i++)
if (i < md5string.Length)
newIVKey[i] = toByte( md5string[i]);