hash - Can't get OAuth signature for Twitter with PHP base64_encode -
i'm working through twitter's creating signature doc.
i've taken example signature base string, , example signing key, , passed hash_hmac function, recommended in doc:
$sig_base_str = 'post&https%3a%2f%2fapi.twitter.com%2f1%2fstatuses%2fupdate.json&include_entities%3dtrue%26oauth_consumer_key%3dxvz1evfs4weeptgefphbog%26oauth_nonce%3dkyjzvbb8y0zfabxswbwovy3uysq2ptgmzenu2vs4cg%26oauth_signature_method%3dhmac-sha1%26oauth_timestamp%3d1318622958%26oauth_token%3d370773112-gmhxmagyylbnetikzernfsmkpr9eymzes9wejaeb%26oauth_version%3d1.0%26status%3dhello%2520ladies%2520%252b%2520gentlemen%252c%2520a%2520signed%2520oauth%2520request%2521'; $sig_key = 'kacsoqf21fu85e7zjz7zn2u4zrhfv3wpwpaoe3z7kbw&lswwdouaivs8ltytt5jkrh4j50vupvvhtr2ypi5ke'; $sha = hash_hmac('sha1', $sig_base_str, $sig_key); $sha = strtoupper($sha); $output = str_split($sha,2); $output = implode(' ',$output); echo $output;
this gives me exact same binary in example: b6 79 c0 af 18 f4 e9 c5 87 ab 8e 20 0a cd 4e 48 a9 3f 8c b6
.
now, doc says convert base64. believe can use php's base64_encode()
function:
$sha = hash_hmac('sha1', $sig_base_str, $sig_key); echo base64_encode($sha);
but gives me incorrect value oauth_signature:
yjy3owmwywyxogy0ztljntg3ywi4ztiwmgfjzdrlndhhotnmogning==
view http://ideone.com/bu0czi see function in action.
what doing wrong? note, i've tried convert uppercase , include spaces before base64_encode()
function. i've been having troubles using twitter api, , think it's because can't signature correct, in examples in docs.
i getting correct hashed value in hexidecimal characters, needed them in raw binary data:
$sha = hash_hmac('sha1', $sig_base_str, $sig_key, true); echo base64_encode($sha);
outputs: tnnarxj06cwhq44gcs1oskk/jly=
should in twitter docs.
got answer looking twitteroauth library: https://github.com/abraham/twitteroauth/blob/master/twitteroauth/oauth.php#l116
Comments
Post a Comment