I have some C#/.NET code that encrypts and decrypts data using TripleDES encryption. It sticks to the sample code provided at MSDN pretty closely. The encryption piece looks like the following:
TripleDESCryptoServiceProvider _desProvider = new TripleDESCryptoServiceProvider();
//bytes for key and initialization vector
//keyBytes is 24 bytes of stuff, vectorBytes is 8 bytes of stuff
byte[] keyBytes;
byte[] vectorBytes;
FileStream fStream = File.Open(locationOfFile, FileMode.Create, FileAccess.Write);
CryptoStream cStream = new CryptoStream(fStream,
_desProvider.CreateEncryptor(keyBytes, vectorBytes),
CryptoStreamMode.Write);
BinaryWriter bWriter = new BinaryWriter(cStream);
//write out encrypted data
//raw data is a few bytes of binary information
byte[] rawData;
bWriter.Write(rawData);
With encrypting and decrypting in C#, this all works like a charm. The problem is I need to write a small Win32 utility that will duplicate the encryption above. I have tried several methods using the CryptoAPI, and I simply do not get output that the .NET piece can decrypt, no matter what I do. Can someone please tell me what the equivalent C++ code is that will produce the same output?
I am not certain just what methods of the CryptoAPI the .NET functions use to encrypt the data. What options are used, and what method of generating the key is used?
Before someone suggests that I just write it in C# anyway, or create some common library bridge for them, those options are unfortunately off the table. It really has to work in Win32 with .NET and without using a DLL. I have some leeway in changing the C# code.
I apologize in advance if this is bone-headed, as I am new to encryption.