note 128038 added to function.hash-hmac
| From: | pbuttelli at tutanota dot com | Date: | Wed, 21 Dec 2022 21:23:31 +0000 |
| Subject: | note 128038 added to function.hash-hmac | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219994@lists.php.net to get a copy of this message | ||
While implementing a TOTP application, please note that hash_hmac() must receive data in binary, not
in a hexadecimal string, to generate a valid OTP across platforms.
This problem can be easily fixed by converting a hexadecimal string to its binary form before
passing it to hash_hmac().
<?php
$time = hex2bin('0000000003523f77'); // time must be in this "hexadecimal and
padded" form
$key = hex2bin('bb57d1...'); // 160-bits = 40-digit hexadecimal (4 bits) = 32-digit base32
(5 bits)
hash_hmac('sha1', $time, $key);
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.175 (proxied: 2804:14c:5d80:95bd:5d49:f6d3:4861:1072)
----
Manual Page -- https://php.net/manual/en/function.hash-hmac.php
Edit -- https://main.php.net/note/edit/128038
Del: integrated -- https://main.php.net/note/delete/128038/integrated
Del: useless -- https://main.php.net/note/delete/128038/useless
Del: bad code -- https://main.php.net/note/delete/128038/bad+code
Del: spam -- https://main.php.net/note/delete/128038/spam
Del: non-english -- https://main.php.net/note/delete/128038/non-english
Del: in docs -- https://main.php.net/note/delete/128038/in+docs
Del: other reasons-- https://main.php.net/note/delete/128038
Reject -- https://main.php.net/note/reject/128038
Search -- https://main.php.net/manage/user-notes.php