-1

I need to calculate Md5 hash in php for the GetReport file received from Amazon GetReport call and match with Content-md5 hash string received in GetReport response header to check the integrity of the file. The problem is i can't figure out how to calculate md5 hash for the report file received via Amazon GetReport call.

I'm using Guzzle for this GetReport Api Call

thanks

aynber
  • 22,380
  • 8
  • 50
  • 63
  • To give you a great answer, it might help us if you have a glance at [ask] if you haven't already. It might be also useful if you could provide a [mcve]. – Mat Jan 18 '17 at 09:56

1 Answers1

0

Not sure if this would work. Let's assume $response is the Guzzle\Http\Message\Response object:

$expectedContentMd5 = $response->getHeader('Content-MD5');
$calculatedContentMd5 = base64_encode(md5($response->getBody(), true));

if($expectedContentMd5 === $calculatedContentMd5) {
    //verified, do your tasks here
} else {
    echo 'MD5 not matched';
    exit;
}

Inspration from: https://github.com/iFixit/php-amazon-mws-reports/blob/8aef4aede236b36ca57432f82e493f0d6e4f6200/src/MarketplaceWebService/Client.php#L964

Notice in AWS, the Content-MD5 field is the base64-encoded value of the binary md5 hash of the data.

Lionel Chan
  • 7,894
  • 5
  • 40
  • 69