public byte[] Decrypt(byte[] file)
{
Twofish fish = new Twofish();
fish.Mode = CipherMode.ECB;
byte[] dummy = { };
//create Twofish Decryptor from our twofish instance
ICryptoTransform decrypt = fish.CreateDecryptor(key, dummy);
System.IO.MemoryStream msD = new System.IO.MemoryStream();
//create crypto stream set to read and do a Twofish decryption transform on incoming bytes
CryptoStream cryptostreamDecr = new CryptoStream(msD, decrypt, CryptoStreamMode.Write);
//write out Twofish encrypted stream
cryptostreamDecr.Write(file, 0, file.Length);
cryptostreamDecr.Close();
byte[] buf = msD.GetBuffer();
// TODO: It might be pretty dangerous to cut on the size of the input buffer
// because of the padding some bytes might be added. However these bytes will
// be only zeros (External.Twofish uses Padding.Zero) so zeros should be OK.
Array.Resize(ref buf, file.Length);
// We can not remove any other padding bytes because we can not distinuish between
// bytes added by the crypto algo and bytes belonging to the original unecrtypted file.
return buf;
}