creation of private keys for ECDSA from hex string e.g. "00112233445566778899AABBCCDDEEFF"

158 views
Skip to first unread message

graeme milligan

unread,
Dec 1, 2014, 10:18:55 AM12/1/14
to cryptop...@googlegroups.com
Hi,
I am new to cryptopp and have been struggling for a while with the creation of  private keys for ECDSA signing.

I have a private key in the format "E4A6CFB431471CFCAE491FD566D19C87082CF9FA7722D7FA24B2B3F5669DBEFB". This is stored as a string.

I want to use this to sign a text block using ECDSA.  My code looks a bit like this

string Sig::genSignature(const string& privKeyIn, const string& messageIn)
{


 
AutoSeededRandomPool prng;
 ECDSA
<ECP, SHA256>::PrivateKey privateKey;
 privateKey
.AccessGroupParameters().Initialize(ASN1::secp256r1());
 privateKey
.Load(StringSource(privKeyIn, true, NULL).Ref());
 
//privateKey.Save(privateKeyBQ);
 
 
//privateKey.SetPrivateExponent(CryptoPP::Integer("4127861661178866478914975717021461"));
 ECDSA
<ECP, SHA256>::Signer signer(privateKey);
 
// Determine maximum size, allocate a string with that size
 size_t siglen
= signer.MaxSignatureLength();
 
string signature(siglen, 0x00);


 
byte message[] = "test";
 
unsigned int messageLen = sizeof(message);


 
// Sign, and trim signature to actual size
 siglen
= signer.SignMessage(prng, (const byte *) messageIn.data(), (size_t) messageIn.length(), (byte*)signature.data());
 signature
.resize(siglen);
 cout
<< signature.data() << endl;
 
return signature;
}


This code generates the following error in Visual studio on the when I try to do privateKey.load(...)

First-chance exception at 0x7693C42D in DLLTest.exe: Microsoft C++ exception: CryptoPP::BERDecodeErr at memory location 0x0033EEA8.
Unhandled exception at 0x7693C42D in DLLTest.exe: Microsoft C++ exception: CryptoPP::BERDecodeErr at memory location 0x0033EEA8.


I amg uessing I am doing somethign a bit stupid... any help would be great???

PS I had a similar issue using ECDH for GMAC generation but ghot round this by saving the key as a SECByteBlock but this 'trick' doesnt seem to work in this case.

Jeffrey Walton

unread,
Dec 1, 2014, 5:24:00 PM12/1/14
to cryptop...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages