c++ - How does a server obtain the ek and iv arguments from the client, in order to RSA decrypt a message? -


i'm trying use evp utilities in openssl rsa encryption. goal implement seal & open method encrypt using public key , decrypt using private key.

assuming ssl handshake successful , client has public key of server, want client seal message before sending it.

something this:

int crypto::rsaencrypt(const unsigned char *msg, size_t msglen, unsigned char **encmsg, unsigned char **ek, size_t *ekl, unsigned char **iv, size_t *ivl) {     ...     if(!evp_sealinit(rsaencryptctx, evp_aes_256_cbc(), ek, (int*)ekl, *iv, &remotepubkey, 1)) {         return failure;     }      if(!evp_sealupdate(rsaencryptctx, *encmsg + encmsglen, (int*)&blocklen, (const unsigned char*)msg, (int)msglen)) {         return failure;     }     encmsglen += blocklen;      if(!evp_sealfinal(rsaencryptctx, *encmsg + encmsglen, (int*)&blocklen)) {         return failure;     }     ... } 

if understanding correct, evp_sealinit() generate public key encrypted secret key pointed ek , iv corresponding cipher. done on client.

when encrypted message sent server, i'll use decrypt:

int crypto::rsadecrypt(unsigned char *encmsg, size_t encmsglen, unsigned char *ek, size_t ekl, unsigned char *iv, size_t ivl, unsigned char **decmsg) {     ...     if(!evp_openinit(rsadecryptctx, evp_aes_256_cbc(), ek, ekl, iv, key)) {         return failure;     }      if(!evp_openupdate(rsadecryptctx, (unsigned char*)*decmsg + declen, (int*)&blocklen, encmsg, (int)encmsglen)) {         return failure;     }     declen += blocklen;      if(!evp_openfinal(rsadecryptctx, (unsigned char*)*decmsg + declen, (int*)&blocklen)) {         return failure;     }     ... } 

ok, questions is, if server calling decrypt, how reference ek , iv (since created on client)? or generated locally?

i referenced these following openssl api docs seal , open. , 1 sample source code: crypto.cpp.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -