I had looked at the wiki before, but everything I see assumes that the
public key is encoded. I've tried to encode the key parts myself, but
I'm doing something wrong and can't figure out what it is. Here is a
sample piece of code that shows what I've tried.
void Base64Encode(std::string &in, std::string &out)
{
CryptoPP::StringSource(in, true, new CryptoPP::Base64Encoder(new
CryptoPP::StringSink(out),false));
}
void Base64Decode(std::string &in, std::string &out)
{
CryptoPP::StringSource(in, true, new CryptoPP::Base64Decoder(new
CryptoPP::StringSink(out)));
}
void test()
{
// I have base64 encoded n and e public key parts
std::string strb64n="AKvhKNxRU/
+aXwJSoOSmCjldk2YT2mVoH6w1+fprfL8qZ51ZNVPjRSCYHaKtZXgxcCENbsPbUtoV7VL0Z
+dGBsYtWIbQqYGZjlXPgSDNl9BvSfHpJXFVH/HTLfYWKn59E
+CpggHezBsscw5G9xFryqJ7MyrReMtYgGYlAwLK8n8p";
std::string strb64e="EQ==";
std::string strn;
std::string stre;
// decode encoded key parts
Base64Decode(strb64n,strn);
Base64Decode(strb64e,stre);
// load 2 integers with decoded key parts
CryptoPP::Integer intn((byte
*)strn.c_str(),strn.size(),CryptoPP::Integer::SIGNED);
CryptoPP::Integer inte((byte
*)stre.c_str(),stre.size(),CryptoPP::Integer::SIGNED);
std::string encodedpubstr;
CryptoPP::Base64Encoder encout(new
CryptoPP::StringSink(encodedpubstr),false);
// start DER sequence
CryptoPP::DERSequenceEncoder derenc(encout);
// encode n and e - tried both DEREncode and BEREncode
intn.DEREncode(derenc);
inte.DEREncode(derenc);
derenc.MessageEnd();
// output the encoded key - seems to look OK
std::cout << encodedpubstr << std::endl;
// now try to load this DER encoded public key into RSA verifier
CryptoPP::StringSource inpsource(encodedpubstr,true,new
CryptoPP::Base64Decoder);
try
{
// throws BER decode error
CryptoPP::RSASS<CryptoPP::PSS, CryptoPP::SHA>::Verifier
pub(inpsource);
}
catch( CryptoPP::Exception& e )
{
std::cerr << "Error e: " << e.what() << std::endl;
}
catch(...)
{
std::cout << "An error occurred" << std::endl;
}
}
On Feb 24, 11:33 am, "Jeffrey Walton" <[EMAIL PROTECTED]> wrote:
> Hi BlackEye,
>
> http://www.cryptopp.com/wiki/RSA
>
> Jeff
>
> On 2/24/07, BlackEye <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm trying to verify a signature (PSS encoded) on a message that was
> > generated with a 3rd party program. I have the n and e parts of the
> > RSA
> > public key in hex format. How can I load this non-encoded public key
> > into
> > an RSA verifier? I've tried to load up two Integers with the numbers
> > and
> > DEREncode them together, but the verifier keeps throwing a BER decode
> > error
> > when it's initialized. All the examples I have seen have assumed
> > some
> > DER/BER encoding of the key. I'm sure there is some way I can easily
> > do
> > this. Does anyone have any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---