Skip to content

Commit e50adf8

Browse files
authored
add hmac tester to repo (#87)
1 parent f3f4be0 commit e50adf8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
class DocuSign_HMAC
4+
{
5+
/*
6+
* Useful reference: https://www.php.net/manual/en/function.hash-hmac.php
7+
* NOTE: Currently DocuSign only supports SHA256.
8+
*/
9+
private static function ComputeHash($secret,$payload)
10+
{
11+
$hexHash = hash_hmac('sha256',$payload,utf8_encode($secret));
12+
$base64Hash = base64_encode(hex2bin($hexHash));
13+
return $base64Hash;
14+
}
15+
public static function HashIsValid($secret,$payload,$verify)
16+
{
17+
return hash_equals($verify, self::ComputeHash($secret,$payload));
18+
}
19+
}
20+
21+
22+
$hmac = new DocuSign_HMAC();
23+
24+
if ($hmac::HashIsValid("{DocuSign HMAC private key}",file_get_contents("payload.txt"), "{JSON response Signature}")){
25+
echo "Signature matches the HMAC key provided";
26+
}
27+
28+
else
29+
{
30+
31+
echo "Signature does not match the HMAC key provided";
32+
}

0 commit comments

Comments
 (0)