On Thursday, October 10, 2013 11:04:06 AM UTC-4, Sunrise wrote:
>
> Hi, I'd like to use HMAC-SHA1 for implementing OAugh signature generation.
> For this purposes I wanted to use follow sample
>
> AutoSeededRandomPool prng;
>
> SecByteBlock key(16);
> prng.GenerateBlock(key, key.size());
>
> string plain = "HMAC Test";
> string mac, encoded;
>
> /*********************************\
> \*********************************/
>
> // Pretty print key
> encoded.clear();
> StringSource(key, key.size(), true,
> new HexEncoder(
> new StringSink(encoded)
> ) // HexEncoder
> ); // StringSource
>
> cout << "key: " << encoded << endl;
> cout << "plain text: " << plain << endl;
>
> /*********************************\
> \*********************************/
>
> try
> {
> HMAC< SHA1 > hmac(key, key.size());
>
> StringSource(plain, true,
> new HashFilter(hmac,
> new StringSink(mac)
> ) // HashFilter
> ); // StringSource
> }
> catch(const CryptoPP::Exception& e)
> {
> cerr << e.what() << endl;
> exit(1);
> }
>
> /*********************************\
> \*********************************/
>
> // Pretty print
> encoded.clear();
> StringSource(mac, true,
> new HexEncoder(
> new StringSink(encoded)
> ) // HexEncoder
> ); // StringSource
>
> cout << "hmac: " << encoded << endl;
>
> But my programming experience is limited only by procedural programming,
> so i can't understand what size of key i should use
>
HMAC< SHA1 >::DEFAULT_KEYLENGTH should provide you with the key size at
compile time.
Or, you can use DefaultKeyLength at runtime:
size_t keyLen = hmac.DefaultKeyLength().
if it can be changeable and how force this sample takes custom keys.
>
Yep, just swap in what you want. For example HMAC< SHA256 > hmac or HMAC<
Whirlpool > hmac.
Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.