Greetings,
Thanks Da Co.
FINAL Solution:
The php code used by many online API's to sign a data request in which
the signature is hashed with HMAC_SHA256 and base64-encoded is
reproduced via the Crypto++ library as follows:
phpcode:
$signature = base64_encode(hash_hmac("sha256", $string_to_sign,
$private_key, True));
c++:
// private_key and string_to_sign are std::string; private_key_len
and string_to_sign_len are int;
// hmac with sha256
CryptoPP::SHA256 hash;
int dwLen = hash.DIGESTSIZE;
unsigned char hmac[ dwLen ];
memset( hmac, 0x00, dwLen );
CryptoPP::HMAC<CryptoPP::SHA256>((byte*)private_key,
private_key_len).CalculateDigest(hmac, (byte*)string_to_sign,
string_to_sign_len);
// base64
CryptoPP::Base64Encoder baseEncoder;
baseEncoder.Put(hmac,dwLen);
baseEncoder.MessageEnd();
baseEncoder.Get(hmac,dwLen*2);
// to string
stringstream s;
s << hmac;
std::string string_encoded = s.str();
Hindsight, makes it look very straightforward. Wrapping my mind
around what was to be accomplished was the difficult part.
Paul