I am working on the example listed here
I am using the below HMAC_SHA256 code provided by OpenSSL to sign URL's that I pass into it.
#include <openssl/evp.h>
#include <openssl/hmac.h>
unsigned char* hmac_sha256(const void *key, int keylen,
const unsigned char *data, int datalen,
unsigned char *result, unsigned int* resultlen)
{
return HMAC(EVP_sha256(), key, keylen, data, datalen, result, resultlen);
}
The code I have that sets up the example is the following:
const unsigned char* test = "GET\nwebservices.amazon.com\n/onca/xml\nAWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&AssociateTag=mytag-20&ItemId=0679722769&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes%2COffers%2CReviews&Service=AWSECommerceService&Timestamp=2014-08-18T12%3A00%3A00Z&Version=2013-08-01";
unsigned char* result = hmac_sha256("1234567890",strlen("1234567890"),test,strlen((char*)test),NULL,NULL);
char dump[5] = {0};
sprintf(dump, "%02x", result[0]);
printf("%s",dump);
The problem is that I get 8F as an ouput when I am supposed to be getting 6a for "j". I get a warning about signedness of the variable test and I think that is the reason I am not getting the correct output. I have looked around to see how I could initalize the unsigned char* to equal the URL given in the example but it seems like you cannot set literals to unsigned char*'s.
How would I go about correctly unsigning the string and passing it correctly to hmac_sha256()?