簡體   English   中英

object 支持緩沖區 API 需要 sha256 錯誤

[英]object supporting the buffer API required sha256 error

我想 hash 一些 4 位數字,但它給了我(需要支持緩沖區 API 的對象)錯誤

這是我的代碼

 import hashlib
import itertools as it

number=[0,1,2,3,4,5,6,7,8,9]
code = hashlib.sha256()
passwords = list(it.permutations(number, 4))
 #hpass is hash password
for hpass in passwords :
    code.update(passwords)
    
    print(hpass)

output 是

Traceback (most recent call last):
  File "c:\Users\Parsa\Desktop\project\Untitled-2.py", line 11, in <module>
    code.update(passwords)
TypeError: object supporting the buffer API required

hashlib.sha256 實例的更新 function 需要類似字節的 object

用類似字節的 object 更新 hash object。 https://docs.python.org/3/library/hashlib.html

而且似乎在更新時輸入密碼列表

很難知道代碼的意圖。 但我想如果正確的話,你想通過 4 位數字獲得一組哈希值,試試這個。

import hashlib
import itertools as it

number=[0,1,2,3,4,5,6,7,8,9]

passwords = list(it.permutations(number, 4))
# hpass is hash password
for hpass in passwords :
    
    encoded_hpass = ''.join(map(str, hpass)).encode('ascii')
    
    code = hashlib.sha256()
    code.update(encoded_hpass)
    
    print(encoded_hpass)
    print(code.digest())

Output

b'0123'
b'\x1b\xe2\xe4R\xb4mz\r\x96V\xbb\xb1\xf7h\xe8$\x8e\xba\x1bu\xba\xede\xf5\xd9\x9e\xaf\xa9H\x89\x9aj'
b'0124'
b'\x91\xb1\xe2@\xed\x10?)\x1c\x16v\\\xb2\x01\xa9\xe4\xf2\xc2?\xf4\x05pP\xb9\xfdxW\x1f7:\xce='
b'0125'
b'\x17\x9f\x91-Q]\xdb\x97\xa0\x8f\xee\xb4\xe3v\x99aH\xda;\xb7\xcb]\x97K\x81<\x8a\xfb\xdcaf+'
b'0126'
b'\x9d\xa4\x84d|\xdd\xd7\x98]\x9e\xf5\x06\xf9\xbd\x15\x80\xf5\xa8\xdc\x06R8\xdbp\x1b\xc5~\x08\xa3<\\\xa9'
b'0127'
b'h|\xdf<\xae\xaa\x88\x8b\x00\x0e\xdfJ\x01\xd1(\xe3\xb3 &\xb0O\xe2H\xaa0\xab/\xab\xa6\xd3@3'
b'0128'
b'\xee\xb9\xff>\xa6X,\xe2\xbf\x03\xb9\xbb\xff\x95\x88"\x90\xb8\xa8\xe5(\xa3\x91\xbc5i\x17\x92\x8fr\x1c\x06'
b'0129'
b'-\x90|u\xaa\xb2$\x85\x0bkv\xd1^/\xd4q$\x8e\xdfq]\xe8\xf7\x9d\xc8L-A\x1ff?\x88'
b'0132'
b"\xa7H\x02\x8b\x05\x18\xda\x98\xd8\xd2F\xe6\x1a8\x96\xa6w\x05\x97^'\xc3\xa0B\xb1E\r\xa9\\\xe3\x9bU"
b'0134'
....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM