Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It may be that it just doesn't like the very short keys you're using.</p> <p>I found <a href="http://msdn.microsoft.com/en-us/library/aa381969.aspx" rel="nofollow noreferrer">the desktop version of that article</a> which may help, as it has a full example.</p> <p>EDIT:</p> <p>The OP realised from the example that you have to tell CryptGenKey how long the keys are, which you do by setting the top 16-bits of the flags to the number of bits you want to use. If you leave this as 0, you get the default key length. This <em>is</em> documented in the <strong>Remarks</strong> section of the device documentation, and with the <em>dwFlags</em> parameter in the <a href="http://msdn.microsoft.com/en-us/library/aa379941(VS.85).aspx" rel="nofollow noreferrer">desktop documentation</a>. </p> <p>For the Diffie-Hellman key-exchange algorithm, the Base provider defaults to 512-bit keys and the Enhanced provider (which is the default) defaults to 1024-bit keys, on Windows XP and later. There doesn't seem to be any documentation for the default lengths on CE.</p> <p>The code should therefore be:</p> <pre><code>BYTE p[64] = { 139 }; // little-endian, all other bytes set to 0 BYTE g[64] = { 5 }; CRYPT_DATA_BLOB pblob; pblob.cbData = sizeof( p); pblob.pbData = p; CRYPT_DATA_BLOB gblob; gblob.cbData = sizeof( g ); gblob.pbData = g; HCRYPTKEY hKey; if ( ::CryptGenKey( m_hCryptoProvider, CALG_DH_SF, ( 512 &lt;&lt; 16 ) | CRYPT_PREGEN, &amp;hKey ) ) { ::CryptSetKeyParam( hKey, KP_P, ( LPBYTE ) &amp;pblob, 0 ); </code></pre>
    singulars
    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. VO
      singulars
      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