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 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型