Skip to content

IPrivateKey

Jay edited this page Oct 3, 2026 · 2 revisions

IPrivateKey

#include <certpp/crypto/keys.hpp> --- certpp::crypto --- implements IAsymmetricKeyBase

An asymmetric algorithm's private key. Produced by IAsymmetric::createPrivateKey() or SKeyPair::privateKey; never constructed directly.

Methods

virtual ~IPrivateKey() = default

Virtual destructor.

virtual IPublicKeyPtr publicKey() const = 0

Returns: This key's corresponding public key.

Example

Imports a private key, validates it, and derives its public half. checkPrivateKey() is worth calling on anything deserialized: generateKeyPair() runs it for you, createPrivateKey() does not, and it reports why it failed rather than ERET_AGAIN.

// given: const crypto::IAsymmetricPtr& algo, const SReadOnlyByteSpan& keyData
crypto::IPrivateKeyPtr key = algo->createPrivateKey(keyData);
if (!key) {
    return; // not a valid encoding
}

if (algo->checkPrivateKey(key) != ERET_OK) {
    return; // ERET_KEY_PARAM for an off-curve or wrong-subgroup point, and so on
}

crypto::IPublicKeyPtr pub = key->publicKey();
if (!pub) {
    return;
}

crypto::IAsymmetricContextPtr ctx = algo->createContext();
ctx->keyPair(pub, key);

Reference generated from certpp/crypto/keys.hpp at commit 0834b29 (v1.0.1). The header is authoritative --- if this page disagrees with it, the header is right and this page needs regenerating.

Clone this wiki locally