繁体   English   中英

使用Crypto ++获取ECDSA签名

[英]Get ECDSA signature with Crypto++

我必须使用Crypto ++在变量中获取ECDSA签名。
我在启动SignMessage后尝试获取它,但签名为空。
我怎么能得到它?

您是否看过Crypto ++ Wiki? 椭圆曲线数字签名算法有很多东西。

目前尚不清楚您在做什么或出了什么问题,因此这里是Wiki的副本和粘贴内容:

签名:

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

验证:

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 ) {...}

如果您希望验证失败,请尝试:

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
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM