HOTP身份验证器应用程序-缓冲区API错误

时间:2019-06-15 22:00:04

标签: python python-3.x cryptography hmac

我正在尝试制作一个以python实现的身份验证器应用。应该在程序开始时返回原始的SHA-512哈希十六进制摘要,然后每50秒返回一次(使用time.time() % 50)。这是我到目前为止的内容:

from hashlib import sha512
import hmac
from time import time

key = b'Sixteen byte key'
keyobj = hmac.new(key,msg=None,digestmod=sha512)

float_count = lambda: int(time()) / 50

keyobj.update(int(float_count())) # floor() <==> int()
print(keyobj.hexdigest())
while True:
    if float_count % 50 == 0:
        keyobj.update(int(float_count()))
        print(keyobj.hexdigest())

然后给出

Traceback (most recent call last):
  File "/Users/goldentitanium1313/Desktop/ Python_Files/authenticator.py", line 22, in <module>
    keyobj.update(int(float_count())) # floor() <==> int()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/hmac.py", line 102, in update
    self.inner.update(msg)
TypeError: object supporting the buffer API required

0 个答案:

没有答案