[Help-gnutls] Re: Generating an RSA key

Simon Josefsson jas at extundo.com
Mon Oct 30 10:17:36 CET 2006

Brad Hards <bradh at frogmouth.net> writes:

> I'm trying to write some code that generates RSA keys (given either the raw 
> parameters, and also given the exponent and bit size), and then extract 
> various things (bit size, public key), and some I/O in DER and PEM formats.
> I'd prefer it if I could avoid learning the sexp stuff used in libgcrypt. 
> However I can't find the right part of the API.
> Does anyone have a suggestion or example code that they would be willing to 
> share?

Hi!  I'm not aware of any code that does exactly what you want,
although look in lib/x509/privkey.c for some functions that converts
to and from raw RSA keys to PKCS#1 format.

In particular, perhaps gnutls_x509_privkey_export_rsa_raw() and
gnutls_x509_privkey_import_rsa_raw() does something similar to what
you want?

To generate the key, you can use gnutls_x509_privkey_generate() as a
basis for your code, and replace the call to
_gnutls_rsa_generate_params() with a call to your own function that
generates the same values.  They use the libgcrypt mpi_t type, but you
wouldn't have to use the sexp stuff.

Just some ideas..


More information about the Gnutls-help mailing list