2014-01-09 101 views

回答

0

你有沒有看過Crypto ++ wiki? Elliptic Curve Digital Signature Algorithm上有很多東西。

其真不明白你在做什麼或那裏的東西出了問題,所以這裏的副本,並從維基粘貼:

簽名:

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 
); 
相關問題