Public Types | Public Member Functions | Static Public Member Functions

base_crypto::CryptoKeypair Class Reference

An interface for public/private key pairs. More...

#include <libppbase/base_crypto/CryptoKeypair.h>

Inheritance diagram for base_crypto::CryptoKeypair:
base_crypto::CryptoKeypairDSA base_crypto::CryptoKeypairRSA

List of all members.

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 CryptoKeypaircreate (keypairMethod method)
 Creates a new keypair object.
static CryptoKeypaircreate (const char *name)
 Creates a new keypair object.
static keypairMethod getMethodByName (const char *name)
 Gets a keypair method by name.

Detailed Description

An interface for public/private key pairs.

Author:
Christoph Schwarz
Version:
$Id: CryptoKeypair.h 21 2010-09-05 04:18:17Z cschwarz1 $

Member Enumeration Documentation

The checksum methods (algorithms).

Enumerator:
keypairUndef 

unset algorithm

keypairDSA 

DSA algorithm.

keypairRSA 

RSA algorithm.


Member Function Documentation

static CryptoKeypair* base_crypto::CryptoKeypair::create ( keypairMethod  method  )  [static]

Creates a new keypair object.

Parameters:
method the method to use
Returns:
NULL if the method is unknown
static CryptoKeypair* base_crypto::CryptoKeypair::create ( const char *  name  )  [static]

Creates a new keypair object.

Parameters:
name the method to use
Returns:
NULL if the method is unknown
virtual void base_crypto::CryptoKeypair::create ( unsigned  keylen  )  [pure virtual]

Creates a new keypair.

Parameters:
keylen length of the key in bits
void* base_crypto::CryptoKeypair::free ( unsigned char *  buf  )  const

Frees the buffer allocated by getPrivateKey and getPublicKey.

Parameters:
buf the buffer
Returns:
NULL
static keypairMethod base_crypto::CryptoKeypair::getMethodByName ( const char *  name  )  [static]

Gets a keypair method by name.

Parameters:
name the name of the method
Returns:
methodUndef if the method is unknown, otherwise the method ID
virtual keypairMethod base_crypto::CryptoKeypair::getMethodId (  )  const [pure virtual]

Gets the ID of the keypair method.

Returns:
the ID
virtual const char* base_crypto::CryptoKeypair::getMethodName (  )  const [pure virtual]

Gets the name of the keypair method.

Returns:
the name
base::String base_crypto::CryptoKeypair::getPrivateKey (  )  const

Gets the private key.

Returns:
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

Parameters:
rbuf pointer to a pointer to the private key
Returns:
length of the private key in bytes
base::String base_crypto::CryptoKeypair::getPublicKey (  )  const

Gets the public key.

Returns:
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

Parameters:
rbuf pointer to a pointer to the private key
Returns:
length of the private key in bytes
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.

Returns:
size in bytes
virtual void base_crypto::CryptoKeypair::readPrivateKey ( FILE *  file,
bool  pem 
) [pure virtual]

Reads the private key from a file.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
data the data (usually the result of a CryptoChecksum)
method message digest algorithm used to generate data
Returns:
the signature generated
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.

Parameters:
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
Returns:
length of the signature
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.

Parameters:
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
Returns:
true if the signature is valid, false if not
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.

Parameters:
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
Returns:
true if the signature is valid, false if not
virtual void base_crypto::CryptoKeypair::writePrivateKey ( FILE *  file,
bool  pem 
) [pure virtual]

Writes the private key to a file.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
file open file to write to
pem true to write in PEM format, false for binary format

The documentation for this class was generated from the following file: