# Poco::Crypto

# class KeyPair

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

## Description

This is a parent class for classes storing a key pair, consisting of private and public key. Storage of the private key is optional.

If a private key is available, the KeyPair can be used for decrypting data (encrypted with the public key) or computing secure digital signatures.

## Inheritance

Known Derived Classes: ECKey, RSAKey

## Member Summary

Member Functions: impl, name, operator =, save, size, type

## Enumerations

### Type

KT_RSA = KeyPairImpl::KT_RSA_IMPL

KT_EC = KeyPairImpl::KT_EC_IMPL

## Constructors

### KeyPair

explicit KeyPair(
KeyPairImpl::Ptr pKeyPairImpl = nullptr
);

Extracts the RSA public key from the given certificate.

### KeyPair

KeyPair(
const KeyPair & other
);

Copy constructor.

### KeyPair

KeyPair(
KeyPair && other
) noexcept;

Move constructor.

## Destructor

### ~KeyPair

virtual ~KeyPair();

Destroys the KeyPair.

## Member Functions

### impl

KeyPairImpl::Ptr impl() const;

Returns the impl object.

### name

const std::string & name() const;

Returns key pair name

### operator =

KeyPair & operator = (
const KeyPair & other
);

Assignment.

### operator =

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

Move assignment.

### save

virtual void save(
const std::string & publicKeyPairFile,
const std::string & privateKeyPairFile = "",
const std::string & privateKeyPairPassphrase = ""
) const;

Exports the public and private keys to the given files.

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

### save

virtual void save(
std::ostream * pPublicKeyPairStream,
std::ostream * pPrivateKeyPairStream = nullptr,
const std::string & privateKeyPairPassphrase = ""
) const;

Exports the public and private key to the given streams.

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

### size

virtual int size() const;

Returns the RSA modulus size.

### type

Type type() const;

Returns key pair type