I'm writing an application in C# that needs to decrypt some data that was encrypted by some legacy software. The legacy code loops over the unencrypted bytes in chunks of 8 and encrypts them via TripleDES in CBC mode. It then handles the remaining bytes by using TripleDES CFB, using a block size of the remaining amount (in this specific case, 2).
I can unencrypt the data from the first phase fine in C# using System.Security.Cryptography.TripleDES, since it allows for block sizes of 64 bits (8 bytes). The TripleDES class won't allow for a block size of 16 bits, however. The following code throws an error that says "Specified block size is not valid for this algorithm":
TripleDES provider = TripleDESCryptoServiceProvider.Create();
provider.Mode = CipherMode.CFB;
provider.BlockSize = 16; // exception thrown here
I'm assuming this is in place due to the weak nature of small block sizes. Unfortunately, it's what I'm stuck with. Are there any free third-party libraries that might support a 16-bit block size for TripleDES/CFB? Or are there any tricks I can use on this data set to make this work? I've checked the DES class to see if it supports 16-bit block sizes, but no dice...
I'm no cryptography expert, so if I end up having to roll my own code for TripleDES (over 2 bytes...grrr), any straight-forward articles on the details of the algorithm would be super helpful.