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 
19 namespace Poco {
20 namespace Crypto {
21 
22 
RSAKey(const EVPPKey & key)23 RSAKey::RSAKey(const EVPPKey& key):
24 	KeyPair(new RSAKeyImpl(key))
25 {
26 }
27 
28 
RSAKey(const X509Certificate & cert)29 RSAKey::RSAKey(const X509Certificate& cert):
30 	KeyPair(new RSAKeyImpl(cert))
31 {
32 }
33 
34 
RSAKey(const PKCS12Container & cont)35 RSAKey::RSAKey(const PKCS12Container& cont):
36 	KeyPair(new RSAKeyImpl(cont))
37 {
38 }
39 
40 
RSAKey(KeyLength keyLength,Exponent exp)41 RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
42 	KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3))
43 {
44 }
45 
46 
RSAKey(const std::string & publicKeyFile,const std::string & privateKeyFile,const std::string & privateKeyPassphrase)47 RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
48 	KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase))
49 {
50 }
51 
52 
RSAKey(std::istream * pPublicKeyStream,std::istream * pPrivateKeyStream,const std::string & privateKeyPassphrase)53 RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
54 	KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase))
55 {
56 }
57 
58 
RSAKey(const RSAKey & other)59 RSAKey::RSAKey(const RSAKey& other):
60 	KeyPair(other)
61 {
62 }
63 
64 
RSAKey(RSAKey && other)65 RSAKey::RSAKey(RSAKey&& other) noexcept:
66 	KeyPair(std::move(other))
67 {
68 }
69 
70 
~RSAKey()71 RSAKey::~RSAKey()
72 {
73 }
74 
75 
operator =(const RSAKey & other)76 RSAKey& RSAKey::operator = (const RSAKey& other)
77 {
78 	KeyPair::operator = (other);
79 	return *this;
80 }
81 
82 
operator =(RSAKey && other)83 RSAKey& RSAKey::operator = (RSAKey&& other) noexcept
84 {
85 	KeyPair::operator = (std::move(other));
86 	return *this;
87 }
88 
89 
modulus() const90 RSAKeyImpl::ByteVec RSAKey::modulus() const
91 {
92 	return impl()->modulus();
93 }
94 
95 
encryptionExponent() const96 RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const
97 {
98 	return impl()->encryptionExponent();
99 }
100 
101 
decryptionExponent() const102 RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const
103 {
104 	return impl()->decryptionExponent();
105 }
106 
107 
108 } } // namespace Poco::Crypto
109