c++ - How to print out the private key in ECDSA by using crypto++? -
i trying use elliptic curve dsa.
in part of "generate private key" in following code using crypto++ library, private exponent printed out in console.
how can print out private key itself?
int main( int, char** ) { autoseededrandompool prng; bytequeue privatekey, publickey, testkey; string message = "do or not. there no try."; ////////////////////////////////////////////////////// // generate private key ecdsa<ecp, sha1>::privatekey privkey; privkey.initialize( prng, secp256r1() ); privkey.save( privatekey ); cout<<"the size : "<<sizeof(privatekey)<<endl; cout<<"output 1 : "<< privkey.getprivateexponent() <<endl; cout<<"output 2 : "<< std::hex << privkey.getprivateexponent() <<endl; cout<<"output 3 : "<< std::hex << &privatekey <<endl; cout<<"output 4 : "<< std::hex << &privkey <<endl; // create public key ecdsa<ecp, sha1>::publickey pubkey; privkey.makepublickey( pubkey ); pubkey.save( publickey ); ////////////////////////////////////////////////////// // load private key (in bytequeue, pkcs#8 format) ecdsa<ecp, sha1>::signer signer( privatekey ); // determine maximum size, allocate string size size_t siglen = signer.maxsignaturelength(); string signature(siglen, 0x00); // sign, , trim signature actual size siglen = signer.signmessage( prng, (const byte*)message.data(), message.size(), (byte*)signature.data() ); signature.resize(siglen); ////////////////////////////////////////////////////// // load public key (in bytequeue, x509 format) ecdsa<ecp, sha1>::verifier verifier( publickey ); bool result = verifier.verifymessage( (const byte*)message.data(), message.size(), (const byte*)signature.data(), signature.size() ); if(result) cout << "verified signature on message" << endl; else cerr << "failed verify signature on message" << endl; return 0; }
Comments
Post a Comment