Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I decrypt a file with Crypto++ that was encrypted with C#
    primarykey
    data
    text
    <p><br>I would like to decrypt a file that I previously encrypted with C# using the TripleDESCryptoServiceProvider. <br>Here's my code for encrypting:</p> <pre><code>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 &lt; 8; ++i) { desIV[i] = (byte)i; } for (int j = 0; j &lt; 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(); } </code></pre> <p>I already found the Crypto++ library and managed to build and link it. So I tried to decrypt the file that was stored with C# after the encryption with the following (native) C++ code:</p> <pre><code>FILE *fp; long len; char *buf; if (_wfopen_s(&amp;fp, _T("MyTest.bin"), _T("rb")) != 0) { return false; } fseek(fp ,0 ,SEEK_END); //go to end len = ftell(fp); //get position at end (length) fseek(fp, 0, SEEK_SET); //go to beg. buf = (char *)malloc(len); //malloc buffer fread(buf, len, 1, fp); //read into buffer fclose(fp); BYTE pIV[] = {0, 1, 2, 3, 4, 5, 6, 7}; BYTE pKey[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; const BYTE* lpData = (const BYTE*)(LPCTSTR)buf; size_t bufferSize = strlen(buf); BYTE* result = (BYTE *)malloc(bufferSize); CFB_FIPS_Mode&lt;DES_EDE2&gt;::Decryption decryption_DES_EDE2_CFB; decryption_DES_EDE2_CFB.SetKeyWithIV(pKey, sizeof(pKey), pIV, sizeof(pIV)); decryption_DES_EDE2_CFB.ProcessString(result, lpData, bufferSize); </code></pre> <p>That code won't decrypt properly. The result after the decryption doesn't match the plain text that was encrypted previously. Any idea about my code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload