31 #define ENSURE_PUBLIC_KEY_LOADED(key) \ 33 if ((key) == nullptr) \ 34 NDN_THROW(Error("Public key has not been loaded yet")); \ 37 #define ENSURE_PUBLIC_KEY_NOT_LOADED(key) \ 39 if ((key) != nullptr) \ 40 NDN_THROW(Error("Public key has already been loaded")); \ 65 : m_impl(make_unique<
Impl>())
93 return static_cast<size_t>(EVP_PKEY_bits(m_impl->key));
104 auto ptr = buf.data();
105 if (d2i_PUBKEY(&m_impl->key, &ptr, static_cast<long>(buf.size())) ==
nullptr)
155 return rsaEncrypt(plainText);
162 PublicKey::getEvpPkey()
const 168 PublicKey::toPkcs8()
const 172 uint8_t* pkcs8 =
nullptr;
173 int len = i2d_PUBKEY(m_impl->key, &pkcs8);
177 auto buffer = make_shared<Buffer>(pkcs8, len);
184 PublicKey::rsaEncrypt(span<const uint8_t> plainText)
const 188 if (EVP_PKEY_encrypt_init(ctx) <= 0)
191 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
196 if (EVP_PKEY_encrypt(ctx,
nullptr, &outlen, plainText.data(), plainText.size()) <= 0)
199 auto out = make_shared<Buffer>(outlen);
200 if (EVP_PKEY_encrypt(ctx, out->data(), &outlen, plainText.data(), plainText.size()) <= 0)
Copyright (c) 2011-2015 Regents of the University of California.
Unknown or unsupported key type.
std::string to_string(const T &val)
RSA key, supports sign/verify and encrypt/decrypt operations.
int getEvpPkeyType(const EVP_PKEY *key)
KeyType
The type of a cryptographic key.
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
#define ENSURE_PUBLIC_KEY_NOT_LOADED(key)
implements an output stream that constructs ndn::Buffer
#define ENSURE_PUBLIC_KEY_LOADED(key)
shared_ptr< const Buffer > ConstBufferPtr