Hi all,
I'm programming a device (MPOS) in C/C++ and I need to send encrypted data via TCP/IP to a socket server written in C#.
Problem:
After encrypting the data (
HelloWorld
) and transmitting it to the server, I always get an exception with the message "
Bad Data
".
Encrypting on the device is straight forward:
DoEncryption((char*)secBuffer,length,_3DES_ENCRYPTION,key);
From the C# side, I'm using the Generic Symmetric Algorithm Helper.
(
Generic SymmetricAlgorithm Helper[
^]).
var keyString = "012345678901234567891234";
var key = Encoding.UTF8.GetBytes(keyString);
var sec = new Utilities.Crypto.SymmetricCryptography<TripleDESCryptoServiceProvider>(key, null);
var d1 = File.ReadAllBytes(@"c:\raw.txt");
var dec2 = sec.Decrypt(enc2);
For one thing, no IV is specified in the C encryption above. I modified the
SymmetricCryptography
's constructor a bit to auto generate the IV.
public SymmetricCryptography(byte[] key, byte[] iv)
{
_key = key;
if (iv == null)
{
_provider.Key = key;
_provider.GenerateIV();
iv = _provider.IV;
}
_iv = iv;
}
How do I get this to work?
Regards,
Richard