Poco::Crypto

class EVPPKey

Library: Crypto
Package: CryptoCore
Header: Poco/Crypto/EVPPKey.h

Description

Utility class for conversion of native keys to EVP. Currently, only RSA and EC keys are supported.

Member Summary

Member Functions: duplicate, isSupported, name, operator !=, operator =, operator ==, operator EVP_PKEY *, operator const EVP_PKEY *, save, type

Constructors

EVPPKey

explicit EVPPKey(
    const std::string & ecCurveName
);

Constructs EVPPKey from ECC curve name.

Only EC keys can be wrapped by an EVPPKey created using this constructor.

EVPPKey

explicit EVPPKey(
    const char * ecCurveName
);

Constructs EVPPKey from ECC curve name.

Only EC keys can be wrapped by an EVPPKey created using this constructor.

EVPPKey

EVPPKey(
    const X509Certificate & cert
);

Constructs EVPPKey from the given certificate.

EVPPKey

EVPPKey(
    const PKCS12Container & cert
);

Constructs EVPPKey from the given container.

EVPPKey

explicit EVPPKey(
    EVP_PKEY * pEVPPKey
);

Constructs EVPPKey from EVP_PKEY pointer. The content behind the supplied pointer is internally duplicated.

EVPPKey inline

template < typename K > explicit EVPPKey(
    K * pKey
);

Deprecated. This function is deprecated and should no longer be used.

Constructs EVPPKey from a "native" OpenSSL (RSA or EC_KEY), or a Poco wrapper (RSAKey, ECKey) key pointer.

EVPPKey

EVPPKey(
    const EVPPKey & other
);

Copy constructor.

EVPPKey

EVPPKey(
    EVPPKey && other
) noexcept;

Move constructor.

EVPPKey

EVPPKey(
    int type,
    int param
);

Creates the EVPPKey. Creates a new public/private keypair using the given parameters. Can be used to sign data and verify signatures.

Suported types:

  • EVP_PKEY_RSA
  • EVP_PKEY_EC

Parameters:

  • for EVP_PKEY_RSA: key length in bits
  • for EVP_PKEY_EC: curve NID

This constructor is not available for OpenSSL version < 1.0.0

EVPPKey

EVPPKey(
    const std::string & publicKeyFile,
    const std::string & privateKeyFile,
    const std::string & privateKeyPassphrase = ""
);

Creates the EVPPKey, by reading public and private key from the given files and using the given passphrase for the private key. Can only by used for signing if a private key is available.

EVPPKey

EVPPKey(
    std::istream * pPublicKeyStream,
    std::istream * pPrivateKeyStream,
    const std::string & privateKeyPassphrase = ""
);

Creates the EVPPKey. Can only by used for signing if pPrivKey is not null. If a private key file is specified, you don't need to specify a public key file. OpenSSL will auto-create it from the private key.

EVPPKey

explicit EVPPKey(
    const std::vector < unsigned char > * publicKey,
    const std::vector < unsigned char > * privateKey,
    unsigned long exponent,
    int type
);

Destructor

~EVPPKey

~EVPPKey();

Destroys the EVPPKey.

Member Functions

duplicate static

static EVP_PKEY * duplicate(
    const EVP_PKEY * pFromKey,
    EVP_PKEY * * pToKey
);

Duplicates pFromKey into *pToKey and returns the pointer to duplicated EVP_PKEY.

isSupported inline

bool isSupported(
    int type
) const;

Returns true if OpenSSL type is supported

name

const std::string & name() const;

Retuns the EVPPKey name.

operator != inline

bool operator != (
    const EVPPKey & other
) const;

Comparison operator. Returns true if public key components and parameters of the other key are different from this key.

Works as expected when one key contains only public key, while the other one contains private (thus also public) key.

operator =

EVPPKey & operator = (
    const EVPPKey & other
);

Assignment operator.

operator =

EVPPKey & operator = (
    EVPPKey && other
) noexcept;

Assignment move operator.

operator == inline

bool operator == (
    const EVPPKey & other
) const;

Comparison operator. Returns true if public key components and parameters of the other key are equal to this key.

Works as expected when one key contains only public key, while the other one contains private (thus also public) key.

operator EVP_PKEY * inline

operator EVP_PKEY * ();

Returns pointer to the OpenSSL EVP_PKEY structure.

operator const EVP_PKEY * inline

operator const EVP_PKEY * () const;

Returns const pointer to the OpenSSL EVP_PKEY structure.

save

void save(
    const std::string & publicKeyFile,
    const std::string & privateKeyFile = "",
    const std::string & privateKeyPassphrase = ""
) const;

Exports the public and/or private keys to the given files.

If an empty filename is specified, the corresponding key is not exported.

save

void save(
    std::ostream * pPublicKeyStream,
    std::ostream * pPrivateKeyStream = 0,
    const std::string & privateKeyPassphrase = ""
) const;

Exports the public and/or private key to the given streams.

If a null pointer is passed for a stream, the corresponding key is not exported.

type inline

int type() const;

Retuns the EVPPKey type NID.