Chapter 59. Private keys

x::gnutls::x509::privkey is a reference-counted object that represents a private key:

#include <x/gnutls/x509_privkey.H>
#include <x/gnutls/datumwrapper.H>

x::gnutls::x509::privkey pk(x::gnutls::x509::privkey::create());

pk->generate(GNUTLS_PK_RSA, GNUTLS_SEC_PARAM_NORMAL);
pk->fix();

x::gnutls::datum_t pkd(pk->export_pkcs(GNUTLS_X509_FMT_PEM);
pkd->save("privkey.pem");

An instantiated x::gnutls::x509::privkey is an empty container. A new private key is generated by calling generate() followed by fix(). This is a lengthy process, see the class reference for more information regarding progress indication, and other class methods.