Hi Bjoern,
please see my comments below:
(rather Qt and memory related)
On Thu, Aug 23, 2012 at 03:12:55PM +0200, Bjoern Schiessle wrote:
>
> QMap<QString, QString> Encryption::key2pem(RSA *rsa, QString password)
> {
> QMap<QString, QString> keypair;
> BUF_MEM *bptr;
> BIO *pubBio = BIO_new(BIO_s_mem());
> BIO *privBio = BIO_new(BIO_s_mem());
>
> PEM_write_bio_RSA_PUBKEY(pubBio, rsa);
> PEM_write_bio_RSAPrivateKey(privBio, rsa, EVP_aes_128_cfb(),NULL,
> 0, 0, password.toLocal8Bit().data());
The following block can be simplified:
>
> BIO_get_mem_ptr(pubBio, &bptr);
> char *pubKey = (char *)malloc(bptr->length+1);
> memcpy(pubKey, bptr->data, bptr->length);
> pubKey[bptr->length] = 0;
BIO_get_mem_ptr(pubBio, &bptr);
keypair["publickey"] = QString::fromAscii(bptr->data, bptr->length);
>
> BIO_get_mem_ptr(privBio, &bptr);
> char *privKey = (char *)malloc(bptr->length+1);
> memcpy(privKey, bptr->data, bptr->length);
> privKey[bptr->length] = 0;
BIO_get_mem_ptr(privBio, &bptr);
keypair["privatekey"] = QString::fromAscii(bptr->data, bptr->length);
>
> keypair["privatekey"] = QString(privKey);
> keypair["publickey"] = QString(pubKey);
/* this would be required in your code */
free(privKey);
free(pubKey);
Cheers
Christian
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]