Poco::Crypto

class EVPPKey

File Information

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, 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

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
);

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(
    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.

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

isSupported inline

bool isSupported(
    int type
) const;

Returns true if OpenSSL type is supported

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.

Securely control IoT edge devices from anywhere   Connect a Device