Next: , Up: Abstract key types   [Contents][Index]


6.8.1 Public keys

An abstract gnutls_pubkey_t can be initialized using the functions below. It can be imported through an existing structure like gnutls_x509_crt_t, or through an ASN.1 encoding of the X.509 SubjectPublicKeyInfo sequence.

Function: int gnutls_pubkey_import_x509 (gnutls_pubkey_t key, gnutls_x509_crt_t crt, unsigned int flags)

key: The public key

crt: The certificate to be imported

flags: should be zero

This function will import the given public key to the abstract gnutls_pubkey_t structure.

Returns: On success, GNUTLS_E_SUCCESS (0) is returned, otherwise a negative error value.

Since: 2.12.0

gnutls_pubkey_import_openpgp
gnutls_pubkey_import_pkcs11
gnutls_pubkey_import_pkcs11_url
gnutls_pubkey_import_privkey
gnutls_pubkey_import
Function: int gnutls_pubkey_export (gnutls_pubkey_t key, gnutls_x509_crt_fmt_t format, void * output_data, size_t * output_data_size)

key: Holds the certificate

format: the format of output params. One of PEM or DER.

output_data: will contain a certificate PEM or DER encoded

output_data_size: holds the size of output_data (and will be replaced by the actual size of parameters)

This function will export the public key to DER or PEM format. The contents of the exported data is the SubjectPublicKeyInfo X.509 structure.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN CERTIFICATE".

Returns: In case of failure a negative error code will be returned, and 0 on success.

Since: 2.12.0

Additional functions are available that will return information over a public key.

gnutls_pubkey_get_pk_algorithm
gnutls_pubkey_get_preferred_hash_algorithm
gnutls_pubkey_get_key_id

Next: , Up: Abstract key types   [Contents][Index]