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; }