Hi all,
I'm trying to decrypt a file in unmanaged C++ that was previously encrypted with C# TripleDESCryptoServiceProvider. Unfortunately I do not have a clue how to do that with the Microsoft Crypt API (advapi32.lib). Here is the C# code that I use to encrypt the data:
private static void EncryptData(MemoryStream streamToEncrypt)
{
// initialize the encryption algorithm
TripleDES algorithm = new TripleDESCryptoServiceProvider();
byte[] desIV = new byte[8];
byte[] desKey = new byte[16];
for (int i = 0; i < 8; ++i)
{
desIV[i] = (byte)i;
}
for (int j = 0; j < 16; ++j)
{
desKey[j] = (byte)j;
}
FileStream outputStream = new FileStream(TheCryptedSettingsFilePath, FileMode.OpenOrCreate, FileAccess.Write);
outputStream.SetLength(0);
CryptoStream encStream = new CryptoStream(outputStream, algorithm.CreateEncryptor(desKey, desIV),
CryptoStreamMode.Write);
// write the encrypted data to the file
encStream.Write(streamToEncrypt.ToArray(), 0, (int)streamToEncrypt.Length);
encStream.Close();
outputStream.Close();
}
As you can see the Key and the IV is quite simple (just for testing purpose). So my question is, how do I decrypt that file in C++? I know that the TripleDESCryptoServiceProvider is just a wrapper for the Crypt API, so it cannot be that difficult to solve this problem.
Does anyone ever did something like that and can help me?
Thx Simon