public static function Braintree_Digest::_hmacSha1 in Commerce Braintree 7
3 calls to Braintree_Digest::_hmacSha1()
- Braintree_Digest::hexDigest in braintree_php/
lib/ Braintree/ Digest.php - Braintree_DigestTest::testHmacSha1 in braintree_php/
tests/ unit/ DigestTest.php - Braintree_DigestTest::testHmacSha1_again in braintree_php/
tests/ unit/ DigestTest.php
File
- braintree_php/
lib/ Braintree/ Digest.php, line 45
Class
- Braintree_Digest
- Digest creates an HMAC-SHA1 hash for encrypting messages
Code
public static function _hmacSha1($message, $key) {
$pack = 'H40';
$keyDigest = sha1($key, true);
$innerPad = str_repeat(chr(0x36), 64);
$outerPad = str_repeat(chr(0x5c), 64);
for ($i = 0; $i < 20; $i++) {
$innerPad[$i] = $keyDigest[$i] ^ $innerPad[$i];
$outerPad[$i] = $keyDigest[$i] ^ $outerPad[$i];
}
return sha1($outerPad . pack($pack, sha1($innerPad . $message)));
}