Genscripter P

Genscripter P

  • NA
  • 17
  • 688

Trying to decrypt TripleDES file using C#

Jul 9 2019 4:25 PM
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)
  1. string plaintext = "";  
  2. using (TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider())  
  3. {  
  4. tdes.Mode = CipherMode.ECB;  
  5. tdes.Padding = PaddingMode.PKCS7;  
  6. MD5CryptoServiceProvider MD5b = new MD5CryptoServiceProvider();  
  7. ICryptoTransform decryptor = tdes.CreateDecryptor(FBArr, FBArr);  
  8. using (MemoryStream ms = new MemoryStream(p1))  
  9. {  
  10. using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))  
  11. {  
  12. using (StreamReader reader = new StreamReader(cs))  
  13. plaintext = reader.ReadToEnd();  
  14. }  
  15. }  
  16. }  
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. The decryption looks a lot like this:
PK \2\5\1\5\1\8\2\4\2\0\?n?\Rotate??????????????%??8p??(u??Z??%??8p??(u??Z??%??8p??(u??Z\0\0\0\0\0\0\0\0\0\0\0\RotatePKRotate
 
As you can see, some of the text at the beginning and end of the file is good, and some words are showing up. But the middle is crazy. Why can't I decrypt all the file?
 
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.

Answers (2)