Yeah, it sounds correct. But since it’s an old application code & we are not sure why was it done so, we are little worried to change. Can you please take a look the attachment which has the complete flow, and provide your views which helps us to change it to PEM_read_PrivateKey()
or variants as you suggested Regards, Sunil From: Thulasi Goriparthi <thulasi.goriparthi@xxxxxxxxx>
NOTICE: This email was received from an EXTERNAL sender Isn't it obvious to use PEM_read_PrivateKey() or variants to load the private key as EVP_PKEY and use EVP_PKEY_decrypt* as specified in
https://www.openssl.org/docs/man1.0.2/man3/EVP_PKEY_decrypt.html ? Thanks, Thulasi. On Fri, 29 Jan 2021 at 16:59, Narayana, Sunil Kumar <sanarayana@xxxxxxxx> wrote:
Notice: This e-mail together with any attachments may contain information of Ribbon Communications Inc. and its Affiliates that is confidential and/or proprietary for the sole use of the intended recipient. Any review, disclosure, reliance or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please notify the sender immediately and then delete all copies, including any attachments. |
bool DecryptSignature( string publicKey, string signature, string & keyDecrypted) { ostringstream pem; pem << "-----BEGIN PUBLIC KEY-----" << endl; while (publicKey.length() > 64) { pem << publicKey.substr(0,64) << endl; publicKey.erase(0,64); } if ( !publicKey.empty() ) { pem << publicKey << endl; } pem << "-----END PUBLIC KEY-----" << endl; RSA* rsa= CreateRSAPubKey(pem.str().c_str() ); if ( rsa == NULL ) { return false; } char *buffer; uint32 len; Base64Decode(signature, &buffer, &len ); int32 decryptedLen=RSA_size(rsa); unsigned char decrypted[decryptedLen+1]; int retlen = RSA_public_decrypt(len, (unsigned char*)buffer,decrypted,rsa, RSA_PKCS1_PADDING) ; RSA_free(rsa); free(buffer); if ( retlen > 0 ) { //lint -e{571} Suspicious cast - decrypted contains ascii bytes representation of hash of signature keyDecrypted=string((char*)decrypted, (size_t) retlen ); return true; } else { return false; } } RSA* CreateRSAPubKey(const char* key) { RSA *rsa = NULL; BIO *keybio ; keybio = BIO_new_mem_buf((void*)key, -1); // !!! if (!keybio) { return NULL; } rsa = PEM_read_bio_RSA_PUBKEY(keybio, NULL, NULL, NULL); // !!! if(!rsa ) { return NULL; } BIO_free(keybio); // !!! return rsa; }