signing and verifying signatures of ASN1-format objects

To examine a public key stored in pem format, use

asn1parse -offset 25 -length 75 
where key.pem is the name of the key file.  This will show you the
modulus and exponent of the key.

For more information on the ASN1 format, see the PKCS documents at RSA Data Security.

For a full list of all routines exported from the crypto library, see util/crypto.num and util/ssl.num in the SSLeay distribution.

The routines for extracting public keys from certificates and certificate requests are EVP_PKEY *X509_REQ_extract_key(X509_REQ *req) and EVP_PKEY *X509_extract_key(X509 *x509).

To verify a signature on a signed ASN.1 object the following routines are provided:

int X509_verify(X509 *a,EVP_PKEY *key);
int X509_REQ_verify(X509_REQ *a,EVP_PKEY *key);
int X509_CRL_verify(X509_CRL *a,EVP_PKEY *key);
int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a,EVP_PKEY *key);

I should mention that EVP_PKEY can be used to hold a public or a private key, since for things like RSA and DSS, a public key is just a subset of what is stored for the private key.

To sign any of the above structures the folowing routines are available:

int X509_sign(X509 *a,EVP_PKEY *key,EVP_MD *md);
int X509_REQ_sign(X509_REQ *a,EVP_PKEY *key,EVP_MD *md);
int X509_CRL_sign(X509_CRL *a,EVP_PKEY *key,EVP_MD *md);
int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *a,EVP_PKEY *key,EVP_MD *md);

where md is the message digest to sign with.

There are all defined in x509.h and all the _sign and _verify functions are actually macros to the ASN1_sign() and ASN1_verify() functions. These functions will put the correct algorithm identifiers in the correct places in the structures.