Also , thanks to Andrey V.
http://andreyvitdev.blogspot.com/2005/10/crypto-usage-sample.html



On Tue, Dec 14, 2010 at 10:02 AM, Da Co <[email protected]> wrote:

> http://www.codeproject.com/KB/security/hexencdec.aspx
>
>
> On Tue, Dec 14, 2010 at 12:03 AM, Paul Crown <[email protected]>wrote:
>
>> My next attempt is getting a little better.  Now how to base64 encode?
>>
>>   const char *secretId=msg_to_sign.c_str();
>>   int msg_len = strlen( secretId );
>>
>>   CryptoPP::SHA256 sha256hash;
>>   unsigned char hmac[ sha256hash.DIGESTSIZE ];
>>   memset( hmac, 0x00, sha256hash.DIGESTSIZE );
>>   CryptoPP::HMAC<CryptoPP::SHA256>((byte*)privateId,
>> pri_len).CalculateDigest(hmac, (byte*)secretId, msg_len);
>>
>> Thanks.
>>
>> Paul
>>
>>
>> On Dec 13, 7:20 pm, Paul Crown <[email protected]> wrote:
>> > Greetings,
>> >
>> > I would like to incorporate the equivalent of the following php code
>> > snippet in a c++ app.  I have been experimenting and have learned how
>> > to use a number of crypto++ functions.  I have yet, however, to fully
>> > wrap my mind around this snippet.
>> >
>> > I think that I have just figured out that the term "SHA256" is used in
>> > different respects, one as a hash method, and one as a message
>> > encoding method.    Which means that my c++ snippet is useless.
>> >
>> > In summary, I want to calculate HMAC with SHA256 and base64-encoding
>> > in c++, just like demonstrated in the php snippet below.  Can you
>> > please point me in the right direction?
>> >
>> > Thank you.
>> >
>> > Paul
>> >
>> > Php code snippet:
>> >
>> >     // calculate HMAC with SHA256 and base64-encoding
>> >
>> >     $signature = base64_encode(hash_hmac("sha256", $string_to_sign,
>> > $private_key, True));
>> >
>> > c++ snippet:
>> >
>> >    const char *secretId=msg_to_sign.c_str();
>> >    int msg_len = strlen( secretId );
>> >
>> >    // sha256
>> >    CryptoPP::SHA256 sha256hash;
>> >    unsigned char hash[ sha256hash.DIGESTSIZE ];
>> >    memset( hash, 0x00, sha256hash.DIGESTSIZE );
>> >    sha256hash.CalculateDigest(hash, (byte*)secretId, msg_len);  // use
>> > libcrypt0++ library
>> >
>> >    // hmac
>> >    unsigned char hmac[ sha256hash.DIGESTSIZE ];
>> >    memset( hmac, 0x00, sha256hash.DIGESTSIZE );
>> >    CryptoPP::HMAC<CryptoPP::SHA256>((byte*)secretId,
>> > msg_len).CalculateDigest(hmac, hash, sha256hash.DIGESTSIZE);
>>
>> --
>> 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 "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.

Reply via email to