Esempio n. 1
0
function get_signature($str, $key)
{
    $signature = "";
    if (function_exists('hash_hmac')) {
        $signature = hash_hmac("sha1", $str, $key);
    } else {
        $signature = custom_hmac("sha1", $str, $key);
    }
    return $signature;
}
 private function __cram_md5_generate($plaintext)
 {
     #http://hg.dovecot.org/dovecot-1.2/file/84373d238073/src/lib/hmac-md5.c
     #http://hg.dovecot.org/dovecot-1.2/file/84373d238073/src/auth/password-scheme.c cram_md5_generate
     #am i right that the hmac salt is the plaintext password itself?
     $salt = $plaintext;
     if (function_exists('hash_hmac')) {
         //Some providers doesn't offers hash access.
         return hash_hmac('md5', $plaintext, $salt);
     } else {
         return custom_hmac('md5', $plaintext, $salt);
     }
 }
Esempio n. 3
0
 public function build_signature($request, $consumer, $token)
 {
     global $OAuth_last_computed_signature;
     $OAuth_last_computed_signature = false;
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     if (function_exists("hash_hmac")) {
         $computed_signature = base64_encode(hash_hmac('sha1', $base_string, $key, true));
     } else {
         $computed_signature = base64_encode(custom_hmac('sha1', $base_string, $key, true));
     }
     $OAuth_last_computed_signature = $computed_signature;
     return $computed_signature;
 }
Esempio n. 4
0
<?php

set_include_path(dirname(dirname(__FILE__)) . '/lib/');
echo hash_hmac('sha1', $data, $key, false), "\n";
echo custom_hmac('sha1', $data, $key, false), "\n";
function custom_hmac($algo, $data, $key, $raw_output = false)
{
    $algo = strtolower($algo);
    $pack = 'H' . strlen($algo('test'));
    $size = 64;
    $opad = str_repeat(chr(0x5c), $size);
    $ipad = str_repeat(chr(0x36), $size);
    if (strlen($key) > $size) {
        $key = str_pad(pack($pack, $algo($key)), $size, chr(0x0));
    } else {
        $key = str_pad($key, $size, chr(0x0));
    }
    for ($i = 0; $i < strlen($key) - 1; $i++) {
        $opad[$i] = $opad[$i] ^ $key[$i];
        $ipad[$i] = $ipad[$i] ^ $key[$i];
    }
    $output = $algo($opad . pack($pack, $algo($ipad . $data)));
    return $raw_output ? pack($pack, $output) : $output;
}