Get ECDSA signature with Crypto++

前端 未结 1 804
野性不改
野性不改 2021-01-28 10:38

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条回答
  • 2021-01-28 11:01

    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
    );
    
    0 讨论(0)
提交回复
热议问题