1
Answer

DES produces bad data over 50% of the time

Administrator

Administrator

21y
1.9k
1
I am receiving a Crypto BAD DATA exception about 50% of the time I try to read back encrypted data. I am interfacing with Tucows registrar servers, and they require me to connect with encrypted data using DES. Here is the code I have. Like I said, it works ... partially........90% of the time the login packets go through correctly. 20% of the time the following packet successfully encrypts. This is in my send data method, so this is done per packet. I was curious why I was receiving their invalid data error, until I made a function that verified all outgoing data by trying to decrypt it. Instead of receiving an error message from Tucows, it crashes with the CryptoException : Bad Data. As far as I can tell, I am not doing anything wrong, can somebody shine some light on this for me? Thanks! System.IO.MemoryStream ms = new System.IO.MemoryStream(); desProvider.GenerateIV(); byte [] realIV = desProvider.IV; desProvider.Mode = CipherMode.CBC; desProvider.Padding = PaddingMode.PKCS7; ICryptoTransform encrypto = this.desProvider.CreateEncryptor(key,desProvider.IV); // create Crypto Stream that transforms a stream using the encryption CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write); // write out encrypted content into MemoryStream cs.Write(data, 0, data.Length); cs.FlushFinalBlock(); // get the output and trim the '\0' bytes byte[] bytOut = ms.GetBuffer(); int i = 0; for (i = 0; i < bytOut.Length; i++) if (bytOut[i] == 0) break; data = bytOut;
Answers (1)