3#include <cryptopp/hex.h>
4#include <cryptopp/osrng.h>
5#include <cryptopp/rsa.h>
10 CryptoPP::AutoSeededRandomPool rng;
12 CryptoPP::RSAES_OAEP_SHA256_Decryptor privateKey{rng, size};
13 CryptoPP::RSAES_OAEP_SHA256_Encryptor publicKey{privateKey};
15 std::vector<CryptoPP::byte> privateKeyData;
16 CryptoPP::VectorSink privateKeyDataSink{privateKeyData};
17 privateKey.AccessMaterial().Save(privateKeyDataSink);
18 std::string privateKeyStr;
19 CryptoPP::StringSource privateKeyStringSource{privateKeyData.data(), privateKeyData.size(),
true,
new CryptoPP::HexEncoder{
new CryptoPP::StringSink{privateKeyStr}}};
21 std::vector<CryptoPP::byte> publicKeyData;
22 CryptoPP::VectorSink publicKeyDataArraySink{publicKeyData};
23 publicKey.AccessMaterial().Save(publicKeyDataArraySink);
24 std::string publicKeyStr;
25 CryptoPP::StringSource publicKeyStringSource{publicKeyData.data(), publicKeyData.size(),
true,
new CryptoPP::HexEncoder{
new CryptoPP::StringSink{publicKeyStr}}};
27 return std::make_pair(std::move(privateKeyStr), std::move(publicKeyStr));
31 const CryptoPP::RSASS<CryptoPP::PKCS1v15, CryptoPP::SHA256>::Verifier verifier{
32 CryptoPP::VectorSource(
reinterpret_cast<const std::vector<CryptoPP::byte>&
>(publicKey),
true).Ref()
34 return verifier.VerifyMessage(
reinterpret_cast<const CryptoPP::byte*
>(buffer.data()), buffer.size(),
35 reinterpret_cast<const CryptoPP::byte*
>(signature.data()), signature.size());
39 CryptoPP::AutoSeededRandomPool rng;
41 const CryptoPP::RSASS<CryptoPP::PKCS1v15, CryptoPP::SHA256>::Signer signer{
42 CryptoPP::VectorSource(
reinterpret_cast<const std::vector<CryptoPP::byte>&
>(privateKey),
true).Ref()
45 std::vector<std::byte> out;
46 CryptoPP::VectorSource signData{
47 reinterpret_cast<const std::vector<CryptoPP::byte> &
>(buffer),
true,
48 new CryptoPP::SignerFilter{rng, signer,
new CryptoPP::VectorSink{
reinterpret_cast<std::vector<CryptoPP::byte> &
>(out)}}
std::vector< std::byte > signDataWithSHA256PrivateKey(std::span< const std::byte > buffer, std::span< const std::byte > privateKey)
bool verifySHA256PublicKey(std::span< const std::byte > buffer, std::span< const std::byte > publicKey, std::span< const std::byte > signature)
std::pair< std::string, std::string > computeSHA256KeyPair(uint16_t size=2048)