14 using namespace CryptoPP;
18 static OID
RSA_OID(
"1.2.840.113549.1.1.1");
20 PublicKey::PublicKey()
29 PublicKey::PublicKey(
const uint8_t* keyDerBuf,
size_t keyDerSize)
31 StringSource src(keyDerBuf, keyDerSize,
true);
36 PublicKey::encode(CryptoPP::BufferedTransformation& out)
const
42 out.Put(m_key.buf(), m_key.size());
46 PublicKey::decode(CryptoPP::BufferedTransformation& in)
60 BERSequenceDecoder decoder(in);
62 assert(decoder.IsDefiniteLength());
64 DERSequenceEncoder encoder(sink);
65 decoder.TransferTo(encoder, decoder.RemainingLength());
73 StringSource checkedSource(out,
true);
74 BERSequenceDecoder subjectPublicKeyInfo(checkedSource);
76 BERSequenceDecoder algorithmInfo(subjectPublicKeyInfo);
79 algorithm.
decode(algorithmInfo);
82 throw Error(
"Only RSA public keys are supported for now (" +
83 algorithm.
toString() +
" requested)");
87 m_key.assign(out.begin(), out.end());
89 catch (CryptoPP::BERDecodeErr& err)
91 throw Error(
"PublicKey decoding error");
111 CryptoPP::StringSource(key.
get().
buf(), key.
get().size(),
true,
112 new CryptoPP::Base64Encoder(
new CryptoPP::FileSink(os),
true, 64));
std::string toString() const
static OID RSA_OID("1.2.840.113549.1.1.1")
void decode(CryptoPP::BufferedTransformation &in)
uint8_t * buf()
Get pointer to the first byte of the buffer (alternative version)
const Buffer & get() const
std::ostream & operator<<(std::ostream &os, const Data &data)