I've been trying to figure this out. Backstory: Someone gave me an encrypted file. He told me the Key, the MD5 Hash, the padding, and the mode. He encrypted it in Java using a "DESede" SecretKeySpec instance. I'm trying to decrypt the file in C#.
The FBArr is the 24-byte key. P1 = file.readallbytes(path)
string plaintext = "";
using (TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider())
{
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
MD5CryptoServiceProvider MD5b = new MD5CryptoServiceProvider();
ICryptoTransform decryptor = tdes.CreateDecryptor(FBArr, FBArr);
using (MemoryStream ms = new MemoryStream(p1))
{
using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
{
using (StreamReader reader = new StreamReader(cs))
plaintext = reader.ReadToEnd();
}
}
}
As you can see from the code, the MD5b variable doesn't do anything. Also, the IV is just set exactly to the Key. Even with these irrelevancies, I'm able to decrypt half my file. I need to decrypt the rest of the file.
My question is: How are the MD5 hash and IV used to aide in the decryption?
I think the fact that I'm not using my MD5 Hash is the reason why my key isn't fully decrypting the whole file. I completely understand that MD5 and TripleDES is not secure anymore and I shouldn't use this method in the future. I didn't make that call. I just need to resolve this using the encryption that was given to me.