Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the code (just in case someone has googled this topic out):</p> <pre><code>BYTE *spkiData = SPKI; // X.509 ASN.1 encoded SubjectPublicKeyInfo DWORD dwSPKISize = SPKI_SIZE; // 94 bytes for RSA DWORD dwBufSize = 0; // Get buffer size for decoded spki structure CryptDecodeObject(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO, spkiData, dwSPKISize, 0, NULL, &amp;dwBufSize); BYTE* decBuf = new BYTE[dwBufSize]; CryptDecodeObject( X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO, spkiData, dwSPKISize, 0, decBuf, &amp;dwBufSize); // Now decode the RSA Public key itself CERT_PUBLIC_KEY_INFO * spki = (CERT_PUBLIC_KEY_INFO *) decBuf; // Get buffer size for decoded public key structure CryptDecodeObject( X509_ASN_ENCODING, RSA_CSP_PUBLICKEYBLOB, spki-&gt;PublicKey.pbData, spki-&gt;PublicKey.cbData, 0, 0, &amp;dwBufSize); // Get the RSA public key blob BYTE *blobBuf = new BYTE[dwBufSize]; CryptDecodeObject(X509_ASN_ENCODING, RSA_CSP_PUBLICKEYBLOB, spki-&gt;PublicKey.pbData, spki-&gt;PublicKey.cbData, 0, blobBuf, &amp;dwBufSize); // Acquire crypto provider context HCRYPTPROV hCryptProv = NULL; CryptAcquireContext(&amp;hCryptProv, 0, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); // Import key HCRYPTKEY key = NULL; CryptImportKey(hCryptProv, blobBuf, dwBufSize, 0, 0, &amp;key); // Get the key size DWORD dwKeySize; DWORD dwParamSize = sizeof(DWORD); CryptGetKeyParam(key, KP_KEYLEN, (BYTE*) &amp;dwKeySize, &amp;dwParamSize, 0); // we need it in bytes for convenience dwKeySize /= 8; // Now the fun // allocate a buffer of key size BYTE *data = new BYTE[dwKeySize]; // Copy data need to be encrypted // With PKCS#1 padding data length can not exceed keysize - 11 bytes DWORD dataLen = 16; memcpy(data, "0123456789012345", dataLen); CryptEncrypt(key, 0, TRUE, 0, data, &amp;dataLen, dwKeySize) // now convert it to big endian (for the rest of the world) for (int i = 0; i &lt; (dwKeySize / 2); i++) { BYTE c = data[i]; data[i] = data[dwKeySize - 1 - i]; data[dwKeySize - 1 - i] = c; } // now data points to a dwKeySize length block of RSA PKCS#v1.5 encrypted data </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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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