1//
2// RSAKey.cpp
3//
4// Library: Crypto
5// Package: RSA
6// Module: RSAKey
7//
8// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Crypto/RSAKey.h"
16#include <openssl/rsa.h>
17
18
19namespace Poco {
20namespace Crypto {
21
22
23RSAKey::RSAKey(const EVPPKey& key):
24 KeyPair(new RSAKeyImpl(key)),
25 _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
26{
27}
28
29
30RSAKey::RSAKey(const X509Certificate& cert):
31 KeyPair(new RSAKeyImpl(cert)),
32 _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
33{
34}
35
36
37RSAKey::RSAKey(const PKCS12Container& cont):
38 KeyPair(new RSAKeyImpl(cont)),
39 _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
40{
41}
42
43
44RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
45 KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3)),
46 _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
47{
48}
49
50
51RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
52 KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)),
53 _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
54{
55}
56
57
58RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
59 KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)),
60 _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
61{
62}
63
64
65RSAKey::~RSAKey()
66{
67}
68
69RSAKeyImpl::ByteVec RSAKey::modulus() const
70{
71 return _pImpl->modulus();
72}
73
74
75RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const
76{
77 return _pImpl->encryptionExponent();
78}
79
80
81RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const
82{
83 return _pImpl->decryptionExponent();
84}
85
86
87} } // namespace Poco::Crypto
88