Check out following:
EVP_PKEY* create_key(int key_type, int key_size, char* file)
{
EVP_PKEY* key = NULL;
RSA* rsa = NULL;
DSA* dsa = NULL;
BIO* bio_key = NULL;
char key_file[256] = "";
if(! (key = EVP_PKEY_new()))
return NULL;
if(key_type == TYPE_RSA)
{
if(! (rsa = RSA_generate_key(key_size, 0x10001,
key_generation_cb, 0)))
goto err;
if(! EVP_PKEY_assign_RSA(key, rsa))
goto err;
/* RSA_print(bio_stdout, rsa, 0); */
}
else if(key_type == TYPE_DSA)
{
if(! (dsa = DSA_generate_parameters(key_size, NULL, 0, NULL,
NULL, key_generation_cb, 0)))
goto err;
if(! DSA_generate_key(dsa))
goto err;
if(! EVP_PKEY_assign_DSA(key, dsa))
goto err;
/* DSA_print(bio_stdout, dsa, 0); */
}
if(file && strlen(file))
{
strcpy(key_file, file);
strcat(key_file, ".key");
if(! (bio_key = BIO_new_file(key_file, "wb")))
goto err;
if(! i2d_PrivateKey_bio(bio_key, key))
goto err;
if(bio_key)
BIO_free(bio_key);
}
return key;
err:
if(bio_key)
BIO_free(bio_key);
if(key)
EVP_PKEY_free(key);
return NULL;
}
Thanks
Aslam
-----Original Message-----
From: Lidia Castillejo [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 25, 2002 11:14 AM
To: [EMAIL PROTECTED]
Subject: How to generate a dsa key?
Hi,
I would generate a dsa pair keys and store in pem files (private.pem
/public.pem) from the openssl api.
I see in pem.h file and i find:
int DSA_generate_key(DSA *a);
DSA * DSA_generate_parameters(int bits, unsigned char *seed,int
seed_len,
int *counter_ret,
unsigned long *h_ret,void
(*callback)(int,
int, void *),void *cb_arg);
int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
what is the correctly way to use this parameters?
Thanks,
lidia
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]