Get ECDSA signature with Crypto++

限于喜欢 提交于 2019-12-02 18:18:53

问题


I have to get ECDSA signature in variable using Crypto++.
I tried to get it after launching SignMessage but signature is empty.
How could i get it?


回答1:


Have you had a look at the Crypto++ wiki? There's a lot of stuff on Elliptic Curve Digital Signature Algorithm.

Its not really clear what you are doing or where things went wrong, so here's a copy and paste from the wiki:

Signing:

ECDSA<ECP, SHA1>::PrivateKey privateKey;
privateKey.Load(...);

AutoSeededRandomPool prng;
string message = "Yoda said, Do or do not. There is no try.";
string signature;

StringSource ss1( message, true /*pump all*/,
    new SignerFilter( prng,
        ECDSA<ECP,SHA1>::Signer( privateKey ),
        new StringSink( signature )
    ) // SignerFilter
); // StringSource

Verification:

ECDSA<ECP, SHA1>::PublicKey publicKey;
publicKey.Load(...);

// Result of the verification process
bool result = false;

// Exactly what was signed in the previous step
string message = ...;
// Output from the signing operation in the previous step
string signature = ...;

StringSource ss2( signature+message, true /*pump all*/,
    new SignatureVerificationFilter(
        ECDSA<ECP,SHA1>::Verifier(publicKey),
        new ArraySink( (byte*)&result, sizeof(result) )
    ) // SignatureVerificationFilter
);

// Verification failure?
if( !result ) {...}

If you would like the verifcation to throw on a failure, then try:

static const int VERIFICATION_FLAGS = SIGNATURE_AT_BEGIN | THROW_EXCEPTION;
StringSource ss3( signature+message, true /*pump all*/,
    new SignatureVerificationFilter(
        ECDSA<ECP,SHA1>::Verifier(publicKey),
        NULL, /* No need for attached filter */
        VERIFICATION_FLAGS
    ) // SignatureVerificationFilter
);


来源:https://stackoverflow.com/questions/21024399/get-ecdsa-signature-with-crypto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!