Publicstaticfunctionoath_hotp ($ key, $ counter) {$ bin_counterpack (& #39; N * & #39;, 0 ). pack (& #39; N * & #39;, $ counter); Countermustbe64-bitint $ hashhash_hmac (& #39; sha1 & #39;, $ bin_counter, $ key, true ); returnstr_pad (self: oath_truncate ($ h phpc #
Public static function oath_hotp ($ key, $ counter) {$ bin_counter = pack ('N * ', 0 ). pack ('n' * ', $ counter); // Counter must be 64-bit int $ hash = hash_hmac ('sha1', $ bin_counter, $ key, true ); return str_pad (self: oath_truncate ($ hash), self: otpLength, '0', STR_PAD_LEFT);} public static function oath_truncate ($ hash) {$ offset = ord ($ hash [19]) & 0xf; return (ord ($ hash [$ offset + 0]) & 0x7f) <24) | (ord ($ hash [$ offset + 1]) & 0xff) <16) | (ord ($ hash [$ offset + 2]) & 0xff) <8) | (ord ($ hash [$ offset + 3]) & 0xff) % pow (10, 6 );}
Self: otpLength is a variable in the class.