示例#1
0
function bb_attachments_hmac($secret, $hmac)
{
    if (!function_exists('binsha1')) {
        if (version_compare(phpversion(), "5.0.0", ">=")) {
            function binsha1($d)
            {
                return sha1($d, true);
            }
        } else {
            function binsha1($d)
            {
                return pack('H*', sha1($d));
            }
        }
    }
    if (strlen($secret) == 40) {
        $secret = $secret . str_repeat(chr(0), 24);
    }
    $ipad = str_repeat(chr(0x36), 64);
    $opad = str_repeat(chr(0x5c), 64);
    return base64_encode(binsha1(($secret ^ $opad) . binsha1(($secret ^ $ipad) . $hmac)));
}
示例#2
0
function amazon_hmac($stringToSign)
{
    // helper function binsha1 for amazon_hmac (returns binary value of sha1 hash)
    if (!function_exists('binsha1')) {
        if (version_compare(phpversion(), "5.0.0", ">=")) {
            function binsha1($d)
            {
                return sha1($d, true);
            }
        } else {
            function binsha1($d)
            {
                return pack('H*', sha1($d));
            }
        }
    }
    global $aws_secret;
    if (strlen($aws_secret) == 40) {
        $aws_secret = $aws_secret . str_repeat(chr(0), 24);
    }
    $ipad = str_repeat(chr(0x36), 64);
    $opad = str_repeat(chr(0x5c), 64);
    $hmac = binsha1(($aws_secret ^ $opad) . binsha1(($aws_secret ^ $ipad) . $stringToSign));
    return base64_encode($hmac);
}
示例#3
0
 static function create_signature($policy, $secretAccessKey)
 {
     // helper function binsha1 for amazon_hmac (returns binary value of sha1 hash)
     if (!function_exists('binsha1')) {
         if (version_compare(phpversion(), "5.0.0", ">=")) {
             function binsha1($d)
             {
                 return sha1($d, true);
             }
         } else {
             function binsha1($d)
             {
                 return pack('H*', sha1($d));
             }
         }
     }
     if (strlen($secretAccessKey) == 40) {
         $secretAccessKey = $secretAccessKey . str_repeat(chr(0), 24);
     }
     $ipad = str_repeat(chr(0x36), 64);
     $opad = str_repeat(chr(0x5c), 64);
     $hmac = binsha1(($secretAccessKey ^ $opad) . binsha1(($secretAccessKey ^ $ipad) . $policy));
     return base64_encode($hmac);
 }