Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Once you get in the groove of things, CryptoAPI is relatively straightforward to use. The problem is doing it in a way that is compatible with other cryptography libraries (including .NET framework). I have successfully done this before, but it has been a while; the major sticking point is figuring out how to convert a plain text key into a format usable with CryptoAPI (which operates with "key blobs"). Luckily Microsoft has given us <a href="http://support.microsoft.com/kb/228786" rel="nofollow noreferrer">a working, if tedious, example</a>. As for the CryptoAPI way of doing things, here is an example:</p> <pre><code>// 1. acquire a provider context. // the Microsoft Enhanced provider offers the Triple DES algorithm. HCRYPTPROV hProv = NULL; if(CryptAcquireContext(&amp;hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { // 2. generate the key; see Microsoft KB link above on how to do this. HKEY hKey = NULL; if(ImportPlainTextSessionKey(hProv, lpKeyData, cbKeyData, CALG_3DES, &amp;hKey)) { // 3. set the IV. if(CryptSetKeyParam(hKey, KP_IV, lpIVData, 0)) { // 4. read the encrypted data from the source file. DWORD cbRead = 0; while(ReadFile(hSourceFile, buffer, 8192, &amp;cbRead, NULL) &amp;&amp; cbRead) { // 5. decrypt the data (in-place). BOOL bFinal = cbRead &lt; 8192 ? TRUE : FALSE; DWORD cbDecrypted = 0; if(CryptDecrypt(hKey, NULL, bFinal, 0, buffer, &amp;cbDecrypted)) { // 6. write the decrypted data to the destination file. DWORD cbWritten = 0; WriteFile(hDestFile, buffer, cbDecrypted, &amp;cbWritten, NULL); } } } CryptDestroyKey(hKey); hKey = NULL; } CryptReleaseContext(hProv, 0); hProv = NULL; } </code></pre>
 

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