私は cryptopp を初めて使用し、ECDSA 署名用の秘密鍵の作成にしばらく苦労しています。
16 進数でエンコードされたプライベート指数がありE4A6CFB431471CFCAE491FD566D19C87082CF9FA7722D7FA24B2B3F5669DBEFB
ます。これは文字列として格納されます。
これを使用して、ECDSA を使用してテキスト ブロックに署名したいと考えています。私のコードはこのように見えます
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());
ECDSA<ECP, SHA256>::Signer signer(privateKey);
// Determine maximum size, allocate a string with that size
size_t siglen = signer.MaxSignatureLength();
string signature(siglen, 0x00);
// 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;
}
このコードは、privateKey.load(...) を実行しようとすると、Visual Studio で次のエラーを生成します。
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.
私は少しばかげたことをしていると思います...どんな助けでも素晴らしいでしょうか???
PSGMAC生成にECDHを使用して同様の問題がありましたが、キーをSECByteBlockとして保存することでこれを回避しましたが、この「トリック」はこの場合は機能しないようです。