# Poco::Crypto

# class RSAKeyImpl

Library: Crypto
Package: RSA
Header: Poco/Crypto/RSAKeyImpl.h

## Description

class RSAKeyImpl

## Inheritance

Direct Base Classes: KeyPairImpl

All Base Classes: KeyPairImpl, Poco::RefCountedObject

## Member Summary

Member Functions: decryptionExponent, encryptionExponent, getEVPPKey, getRSA, modulus, save, size

Inherited Functions: duplicate, name, referenceCount, release, save, size, type

## Types Aliases

### ByteVec

using ByteVec = std::vector < unsigned char >;

### Ptr

using Ptr = Poco::AutoPtr < RSAKeyImpl >;

## Constructors

### RSAKeyImpl

RSAKeyImpl(
const EVPPKey & key
);

Constructs RSAKeyImpl by extracting the RSA key.

### RSAKeyImpl

RSAKeyImpl(
const X509Certificate & cert
);

Extracts the RSA public key from the given certificate.

### RSAKeyImpl

RSAKeyImpl(
const PKCS12Container & cert
);

Extracts the RSA private key from the given certificate.

### RSAKeyImpl

RSAKeyImpl(
int keyLength,
unsigned long exponent
);

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

### RSAKeyImpl

RSAKeyImpl(
const std::string & publicKeyFile,
const std::string & privateKeyFile,
const std::string & privateKeyPassphrase
);

Creates the RSAKey, 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.

### RSAKeyImpl

RSAKeyImpl(
std::istream * pPublicKeyStream,
std::istream * pPrivateKeyStream,
const std::string & privateKeyPassphrase
);

Creates the RSAKey. 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

### ~RSAKeyImpl

~RSAKeyImpl();

Destroys the RSAKeyImpl.

## Member Functions

### decryptionExponent

ByteVec decryptionExponent() const;

Returns the RSA decryption exponent.

### encryptionExponent

ByteVec encryptionExponent() const;

Returns the RSA encryption exponent.

### getEVPPKey

EVP_PKEY * getEVPPKey();

Returns the OpenSSL EVP_PKEY object.

### getEVPPKey

const EVP_PKEY * getEVPPKey() const;

Returns the OpenSSL EVP_PKEY object.

### getRSA

RSA * getRSA();

Returns the OpenSSL RSA object.

### getRSA

const RSA * getRSA() const;

Returns the OpenSSL RSA object.

### modulus

ByteVec modulus() const;

Returns the RSA modulus.

### save

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

Exports the public and private keys to the given files.

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

See also: Poco::Crypto::KeyPairImpl::save()

### save

void save(
std::ostream * pPublicKeyStream,
std::ostream * pPrivateKeyStream = nullptr,
const std::string & privateKeyPassphrase = ""
) 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.

See also: Poco::Crypto::KeyPairImpl::save()

### size

int size() const;

Returns the RSA modulus size.

See also: Poco::Crypto::KeyPairImpl::size()