Hi,
I think I did it way too complicated. I think the problem was that I
always tried to mimic some openssl php code I know, but I think the
solution I have now is much easier and standard complained:
void Encryption::generateUserKeys(QString password)
{
RSA *rsa;
EVP_PKEY *pkey;
int bits = 1024;
unsigned long exp = RSA_F4;
QMap<QString, QString> keypair;
rsa = RSA_generate_key(bits, exp, NULL, NULL);
pkey = EVP_PKEY_new();
EVP_PKEY_assign_RSA(pkey, rsa);
keypair = key2pem(rsa, password);
RSA_free(rsa);
sendUserKeysToServer(keypair);
}
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());
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(privBio, &bptr);
char *privKey = (char *)malloc(bptr->length+1);
memcpy(privKey, bptr->data, bptr->length);
privKey[bptr->length] = 0;
keypair["privatekey"] = QString(privKey);
keypair["publickey"] = QString(pubKey);
BIO_free_all(pubBio);
BIO_free_all(privBio);
return keypair;
}
Please feel free to commend on it if you think there is still something
to improve.
best wishes,
Björn
--
Björn Schießle <[email protected]>
www: http://schiessle.org
gnupg key: 0x0x2378A753E2BF04F6
fingerprint: 244F CEB0 CB09 9524 B21F B896 2378 A753 E2BF 04F6
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]