An interface for public/private key pairs. More...
#include <libppbase/base_crypto/CryptoKeypair.h>
Public Types | |
enum | keypairMethod { keypairUndef = NID_undef, keypairDSA = NID_dsa, keypairRSA = NID_rsa } |
The checksum methods (algorithms). More... | |
Public Member Functions | |
virtual | ~CryptoKeypair () |
Destructor. | |
virtual void | create (unsigned keylen)=0 |
Creates a new keypair. | |
void * | free (unsigned char *buf) const |
Frees the buffer allocated by getPrivateKey and getPublicKey. | |
virtual keypairMethod | getMethodId () const =0 |
Gets the ID of the keypair method. | |
virtual const char * | getMethodName () const =0 |
Gets the name of the keypair method. | |
base::String | getPrivateKey () const |
Gets the private key. | |
virtual unsigned | getPrivateKey (unsigned char **rbuf) const =0 |
Gets the private key. | |
base::String | getPublicKey () const |
Gets the public key. | |
virtual unsigned | getPublicKey (unsigned char **rbuf) const =0 |
Gets the public key. | |
virtual unsigned | getSize () const =0 |
Returns the size of an ASN.1 encoded signature in bytes. | |
virtual void | readPrivateKey (FILE *file, bool pem)=0 |
Reads the private key from a file. | |
virtual void | readPrivateKey (const char *fname, bool pem)=0 |
Reads the private key from a file. | |
virtual void | readPublicKey (FILE *file, bool pem)=0 |
Reads the private key from a file. | |
virtual void | readPublicKey (const char *fname, bool pem)=0 |
Reads the private key from a file. | |
void | setPrivateKey (const base::String &key) |
Sets the private key of the key pair. | |
virtual void | setPrivateKey (const unsigned char *buf, unsigned len)=0 |
Sets the private key of the key pair. | |
void | setPublicKey (const base::String &key) |
Sets the public key of the key pair. | |
virtual void | setPublicKey (const unsigned char *buf, unsigned len)=0 |
Sets the public key of the key pair. | |
base::String | sign (const base::String &data, CryptoChecksum::checksumMethod method) |
Signs data with the private key. | |
virtual unsigned | sign (const unsigned char *data, unsigned len, CryptoChecksum::checksumMethod method, unsigned char *sig)=0 |
Signs data with the private key. | |
bool | verify (const base::String &data, CryptoChecksum::checksumMethod method, const base::String &sig) |
Verifies a signature generated with the private key by means of the public key. | |
virtual bool | verify (const unsigned char *data, unsigned datalen, CryptoChecksum::checksumMethod method, const unsigned char *sig, unsigned siglen)=0 |
Verifies a signature generated with the private key by means of the public key. | |
virtual void | writePrivateKey (FILE *file, bool pem)=0 |
Writes the private key to a file. | |
virtual void | writePrivateKey (const char *fname, bool pem)=0 |
Writes the private key to a file. | |
virtual void | writePublicKey (FILE *file, bool pem)=0 |
Writes the public key to a file. | |
virtual void | writePublicKey (const char *fname, bool pem)=0 |
Writes the public key to a file. | |
Static Public Member Functions | |
static CryptoKeypair * | create (keypairMethod method) |
Creates a new keypair object. | |
static CryptoKeypair * | create (const char *name) |
Creates a new keypair object. | |
static keypairMethod | getMethodByName (const char *name) |
Gets a keypair method by name. |
An interface for public/private key pairs.
static CryptoKeypair* base_crypto::CryptoKeypair::create | ( | keypairMethod | method | ) | [static] |
Creates a new keypair object.
method | the method to use |
static CryptoKeypair* base_crypto::CryptoKeypair::create | ( | const char * | name | ) | [static] |
Creates a new keypair object.
name | the method to use |
virtual void base_crypto::CryptoKeypair::create | ( | unsigned | keylen | ) | [pure virtual] |
Creates a new keypair.
keylen | length of the key in bits |
void* base_crypto::CryptoKeypair::free | ( | unsigned char * | buf | ) | const |
Frees the buffer allocated by getPrivateKey and getPublicKey.
buf | the buffer |
static keypairMethod base_crypto::CryptoKeypair::getMethodByName | ( | const char * | name | ) | [static] |
Gets a keypair method by name.
name | the name of the method |
virtual keypairMethod base_crypto::CryptoKeypair::getMethodId | ( | ) | const [pure virtual] |
Gets the ID of the keypair method.
virtual const char* base_crypto::CryptoKeypair::getMethodName | ( | ) | const [pure virtual] |
Gets the name of the keypair method.
base::String base_crypto::CryptoKeypair::getPrivateKey | ( | ) | const |
Gets the private key.
virtual unsigned base_crypto::CryptoKeypair::getPrivateKey | ( | unsigned char ** | rbuf | ) | const [pure virtual] |
Gets the private key.
If the pointer pointed to by rbuf is NULL, the function allocates memory to hold the private key data If it is not NULL, no memory is allocated and the buffer is used to store the private key data
rbuf | pointer to a pointer to the private key |
base::String base_crypto::CryptoKeypair::getPublicKey | ( | ) | const |
Gets the public key.
virtual unsigned base_crypto::CryptoKeypair::getPublicKey | ( | unsigned char ** | rbuf | ) | const [pure virtual] |
Gets the public key.
If the pointer pointed to by rbuf is NULL, the function allocates memory to hold the private key data If it is not NULL, no memory is allocated and the buffer is used to store the private key data
rbuf | pointer to a pointer to the private key |
virtual unsigned base_crypto::CryptoKeypair::getSize | ( | ) | const [pure virtual] |
Returns the size of an ASN.1 encoded signature in bytes.
It can be used to determine how much memory must be allocated for a signature.
virtual void base_crypto::CryptoKeypair::readPrivateKey | ( | FILE * | file, | |
bool | pem | |||
) | [pure virtual] |
Reads the private key from a file.
file | open file to read the key from | |
pem | true if the file is in PEM format, false if it is in binary format |
virtual void base_crypto::CryptoKeypair::readPrivateKey | ( | const char * | fname, | |
bool | pem | |||
) | [pure virtual] |
Reads the private key from a file.
fname | file name | |
pem | true if the file is in PEM format, false if it is in binary format |
virtual void base_crypto::CryptoKeypair::readPublicKey | ( | const char * | fname, | |
bool | pem | |||
) | [pure virtual] |
Reads the private key from a file.
fname | file name | |
pem | true if the file is in PEM format, false if it is in binary format |
virtual void base_crypto::CryptoKeypair::readPublicKey | ( | FILE * | file, | |
bool | pem | |||
) | [pure virtual] |
Reads the private key from a file.
file | open file to read the key from | |
pem | true if the file is in PEM format, false if it is in binary format |
void base_crypto::CryptoKeypair::setPrivateKey | ( | const base::String & | key | ) |
Sets the private key of the key pair.
key | the private key |
virtual void base_crypto::CryptoKeypair::setPrivateKey | ( | const unsigned char * | buf, | |
unsigned | len | |||
) | [pure virtual] |
Sets the private key of the key pair.
buf | the private key | |
len | length of the private key |
void base_crypto::CryptoKeypair::setPublicKey | ( | const base::String & | key | ) |
Sets the public key of the key pair.
key | the public key |
virtual void base_crypto::CryptoKeypair::setPublicKey | ( | const unsigned char * | buf, | |
unsigned | len | |||
) | [pure virtual] |
Sets the public key of the key pair.
buf | the public key | |
len | length of the public key |
base::String base_crypto::CryptoKeypair::sign | ( | const base::String & | data, | |
CryptoChecksum::checksumMethod | method | |||
) |
Signs data with the private key.
data | the data (usually the result of a CryptoChecksum) | |
method | message digest algorithm used to generate data |
virtual unsigned base_crypto::CryptoKeypair::sign | ( | const unsigned char * | data, | |
unsigned | len, | |||
CryptoChecksum::checksumMethod | method, | |||
unsigned char * | sig | |||
) | [pure virtual] |
Signs data with the private key.
data | the data (usually the result of a CryptoChecksum) | |
len | length of the data | |
method | message digest algorithm used to generate data | |
sig | the signature generated |
bool base_crypto::CryptoKeypair::verify | ( | const base::String & | data, | |
CryptoChecksum::checksumMethod | method, | |||
const base::String & | sig | |||
) |
Verifies a signature generated with the private key by means of the public key.
data | the data (usually the result of a CryptoChecksum) | |
method | message digest algorithm used to generate data | |
sig | the signature generated with the private key |
virtual bool base_crypto::CryptoKeypair::verify | ( | const unsigned char * | data, | |
unsigned | datalen, | |||
CryptoChecksum::checksumMethod | method, | |||
const unsigned char * | sig, | |||
unsigned | siglen | |||
) | [pure virtual] |
Verifies a signature generated with the private key by means of the public key.
data | the data (usually the result of a CryptoChecksum) | |
datalen | length of the data | |
method | message digest algorithm used to generate data | |
sig | the signature generated with the private key | |
siglen | length of the signature |
virtual void base_crypto::CryptoKeypair::writePrivateKey | ( | FILE * | file, | |
bool | pem | |||
) | [pure virtual] |
Writes the private key to a file.
file | open file to write to | |
pem | true to write in PEM format, false for binary format |
virtual void base_crypto::CryptoKeypair::writePrivateKey | ( | const char * | fname, | |
bool | pem | |||
) | [pure virtual] |
Writes the private key to a file.
fname | file name | |
pem | true to write in PEM format, false for binary format |
virtual void base_crypto::CryptoKeypair::writePublicKey | ( | const char * | fname, | |
bool | pem | |||
) | [pure virtual] |
Writes the public key to a file.
fname | file name | |
pem | true to write in PEM format, false for binary format |
virtual void base_crypto::CryptoKeypair::writePublicKey | ( | FILE * | file, | |
bool | pem | |||
) | [pure virtual] |
Writes the public key to a file.
file | open file to write to | |
pem | true to write in PEM format, false for binary format |