Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate session key based on PUBLICKEYBLOB / PRIVATEKEYBLOB
    primarykey
    data
    text
    <p>My code looks like this, I traced each undefined method here to the functions called with relevant arguments included.</p> <p>I have a hard time wrapping my head around the API. So what I have here is that I can generate public/private keys, and I can generate <strong>a</strong> session key, but how can I generate a session key based on the public key? What am I missing/assuming (wrong) here?</p> <pre><code> void Crypto::GenerateKeyPair( Buffer& publicKey, Buffer& privateKey ) throw(WinError) { /* CryptAcquireContext ( PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) */ CryptContext context = CryptoProviders::NewContext(PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); /* CryptGenKey( AT_KEYEXCHANGE, CRYPT_EXPORTABLE, &key) */ CryptKey key = context.GenerateKeyExchangePair(); /* CryptExportKey( PUBLICKEYBLOB, pPub); */ key.ExportPublicKey(publicKey); /* CryptExportKey( PRIVATEKEYBLOB, pPriv); */ key.ExportPrivateKey(privateKey); } void Crypto::GenerateSessionKey( Buffer& sessionKey ) throw(WinError) { /* CryptAcquireContext ( PROV_RSA_FULL, 0 ) */ CryptContext context = CryptoProviders::NewContext(PROV_RSA_FULL, 0); /* CryptGenKey( CALG_RC4, CRYPT_EXPORTABLE ) */ /* CryptGetUserKey( AT_KEYEXCHANGE ) */ /* CryptExportKey( SIMPLEBLOB ) */ context.GenerateSessionKey(sessionKey); } void Crypto::EncryptData( const Buffer& publicKey, const Buffer& plaintext, Buffer& encrypted ) { /* CryptAcquireContext ( PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) */ CryptContext hProvider(PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); /* CryptImportKey( 0 ) */ CryptKey key = hProvider.ImportKey(publicKey); /* CryptEncrypt() */ key.Encrypt(plaintext, encrypted); } void Crypto::DecryptData( const Buffer& privateKey, const Buffer& encrypted, Buffer& plaintext ) { /* CryptAcquireContext ( PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) */ CryptContext hProvider(PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); /* CryptImportKey( 0 ) */ CryptKey key = hProvider.ImportKey(privateKey); /* CryptDecrypt() */ key.Decrypt(encrypted, plaintext); } </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.
 

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