l919527707 2014-08-22 03:00
浏览 1929

php代码转C#代码,来个会PHP和C#的高手

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是类中的一个变量

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器