libdigidocpp
digidoc::RSACrypt Class Reference

#include <RSACrypt.h>

Collaboration diagram for digidoc::RSACrypt:
Collaboration graph

Public Member Functions

 RSACrypt (X509 *cert, RSA *privateKey)
 RSACrypt (X509 *cert)
 RSACrypt (RSA *privateKey)
 ~RSACrypt ()
std::vector< unsigned char > sign (const Signer::Digest &digest) throw (IOException)
bool verify (int digestMethod, std::vector< unsigned char > digest, std::vector< unsigned char > signature) throw (IOException)

Static Public Member Functions

static RSA * loadRSAPrivateKey (const std::string &path) throw (IOException)

Private Attributes

X509 * cert
RSA * privateKey

Detailed Description

Wrapper for RSA crypto function in OpenSSL. Currently implemented RSA signature verification and signing with private RSA key.

Author
Janari Põld

Definition at line 37 of file RSACrypt.h.

Constructor & Destructor Documentation

digidoc::RSACrypt::RSACrypt ( X509 *  cert,
RSA *  privateKey 
)

Initialize RSA crypter.

Parameters
certX.509 certificate.
privateKeyRSA private key, must match with the provided X.509 certificate.

Definition at line 32 of file RSACrypt.cpp.

digidoc::RSACrypt::RSACrypt ( X509 *  cert)

Initialize RSA crypter.

Parameters
certX.509 certificate.

Definition at line 43 of file RSACrypt.cpp.

digidoc::RSACrypt::RSACrypt ( RSA *  privateKey)

Initialize RSA crypter.

Parameters
privateKeyRSA private key.

Definition at line 54 of file RSACrypt.cpp.

digidoc::RSACrypt::~RSACrypt ( )

Definition at line 63 of file RSACrypt.cpp.

Member Function Documentation

RSA * digidoc::RSACrypt::loadRSAPrivateKey ( const std::string &  path) throw (IOException)
static

Loads RSA private key from file. NB! This struct must be freed using RSA_free() function from OpenSSL or with RSA_scope struct.

Parameters
pathPEM formatted RSA private key file path.
Returns
returns RSA private key parsed from file.
Exceptions
IOExceptionthrows exception if the file does not contain RSA private key.

Definition at line 154 of file RSACrypt.cpp.

References file, and THROW_IOEXCEPTION.

Referenced by testRSASigner().

Here is the caller graph for this function:

std::vector< unsigned char > digidoc::RSACrypt::sign ( const Signer::Digest digest) throw (IOException)

Signs the digest with provided RSA private key.

Parameters
digestMethoddigest method (e.g NID_sha1 for SHA1, see openssl/obj_mac.h).
digestdigest value, this value is signed with the private RSA key.
Returns
returns signature.
Exceptions
IOException

Definition at line 75 of file RSACrypt.cpp.

References THROW_IOEXCEPTION.

Referenced by digidoc::RSASigner::sign().

Here is the caller graph for this function:

bool digidoc::RSACrypt::verify ( int  digestMethod,
std::vector< unsigned char >  digest,
std::vector< unsigned char >  signature 
) throw (IOException)

Verify signature with RSA public key from X.509 certificate.

Parameters
digestMethoddigest method (e.g NID_sha1 for SHA1, see openssl/obj_mac.h).
digestdigest value, this value is compared with the digest value decrypted from the signature.
signaturesignature value, this value is decrypted to get the digest and compared with the digest value provided in digest.
Returns
returns true if the signature value matches with the digest, otherwise false is returned.
Exceptions
IOExceptionthrows exception if X.509 certificate is not missing or does not have a RSA public key.

Definition at line 120 of file RSACrypt.cpp.

References int(), and THROW_IOEXCEPTION.

Here is the call graph for this function:

Member Data Documentation

X509* digidoc::RSACrypt::cert
private

Definition at line 50 of file RSACrypt.h.

RSA* digidoc::RSACrypt::privateKey
private

Definition at line 51 of file RSACrypt.h.


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