RSAKey.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "Poco/Crypto/RSAKey.h"
  14. #include <openssl/rsa.h>
  15. namespace Poco {
  16. namespace Crypto {
  17. RSAKey::RSAKey(const EVPPKey& key):
  18. KeyPair(new RSAKeyImpl(key)),
  19. _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
  20. {
  21. }
  22. RSAKey::RSAKey(const X509Certificate& cert):
  23. KeyPair(new RSAKeyImpl(cert)),
  24. _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
  25. {
  26. }
  27. RSAKey::RSAKey(const PKCS12Container& cont):
  28. KeyPair(new RSAKeyImpl(cont)),
  29. _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
  30. {
  31. }
  32. RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
  33. KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3)),
  34. _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
  35. {
  36. }
  37. RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
  38. KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)),
  39. _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
  40. {
  41. }
  42. RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
  43. KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)),
  44. _pImpl(KeyPair::impl().cast<RSAKeyImpl>())
  45. {
  46. }
  47. RSAKey::~RSAKey()
  48. {
  49. }
  50. RSAKeyImpl::ByteVec RSAKey::modulus() const
  51. {
  52. return _pImpl->modulus();
  53. }
  54. RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const
  55. {
  56. return _pImpl->encryptionExponent();
  57. }
  58. RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const
  59. {
  60. return _pImpl->decryptionExponent();
  61. }
  62. } } // namespace Poco::Crypto