private byte[] EncryptDecrypt(byte[] arCryptoBytes, CryptographicDirection theDirection) { byte[] arOutputBytes; //get our cryptographic providers out MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); TripleDESCryptoServiceProvider my3DES = new TripleDESCryptoServiceProvider(); ICryptoTransform myTransform = null; try { //hash the key my3DES.Key = hashmd5.ComputeHash(BaseKey); my3DES.Mode = CipherMode.ECB; my3DES.Padding = PaddingMode.PKCS7; switch (theDirection) { case CryptographicDirection.Encrypt: myTransform = my3DES.CreateEncryptor(); break; case CryptographicDirection.Decrypt: myTransform = my3DES.CreateDecryptor(); break; } arOutputBytes = myTransform.TransformFinalBlock(arCryptoBytes, 0, arCryptoBytes.Length); } finally { //clear down the objects //the are managed wrappers to unmanaged objects so best to dispose of them properly hashmd5.Clear(); my3DES.Clear(); myTransform.Dispose(); } return(arOutputBytes); }
private byte[] EncryptDecrypt(byte[] arCryptoBytes, CryptographicDirection theDirection) { byte[] arOutputBytes; //get our cryptographic providers out MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); TripleDESCryptoServiceProvider my3DES = new TripleDESCryptoServiceProvider(); ICryptoTransform myTransform = null; try { //hash the key my3DES.Key = hashmd5.ComputeHash(BaseKey); my3DES.Mode = CipherMode.ECB; my3DES.Padding = PaddingMode.PKCS7; switch(theDirection) { case CryptographicDirection.Encrypt: myTransform = my3DES.CreateEncryptor(); break; case CryptographicDirection.Decrypt: myTransform = my3DES.CreateDecryptor(); break; } arOutputBytes = myTransform.TransformFinalBlock(arCryptoBytes, 0, arCryptoBytes.Length); } finally { //clear down the objects //the are managed wrappers to unmanaged objects so best to dispose of them properly hashmd5.Clear(); my3DES.Clear(); myTransform.Dispose(); } return arOutputBytes; }