使用 hashlib python 将数字列表的每个数字散列为 sha256

hash each number of number list to sha256 with hashlib python

我的哈希与标准 sha256 不同

如何在 python 中使用 hashlib 将每个列表编号散列为 sha256?

您可以看到我的结果和其他在线转换器结果:

#hash 9999 from https://emn178.github.io/online-tools/sha256.html
    
    888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05
    
#hash 9999 from https://www.online-convert.com/result#j=96f7a8bb-2c97-4c6c-ae6d-7deda4f62e3c

    888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05

#hash 9999 from https://passwordsgenerator.net/sha256-hash-generator/

    888DF25AE35772424A560C7152A1DE794440E0EA5CFEE62828333A456A506E05





my sha256 hash of 9999:

       
    877f59e9e62b9f0bfdc877653856410990e8aba4ac8b55ad06cd8cf5ecdfbc17

这是我的代码。谁能教我如何解决这个问题?

import CSV
from hashlib import sha256

hash_dic = {}
numbers = []
count = 1

#make number range between 1 t0 9999
while count <= 9999:
    numbers.append(count)
    count += 1

#make hash sha256 dic
for number in numbers:
    hashed = sha256(bytes(number)).hexdigest()
    hash_dic[number] = hashed


#open csv file and maining hashes
with open("Desktop/passwords.csv") as passwrd:
    reader = csv.reader(passwrd)
    for row in reader:
        csv_hash = row[1]
        
        for key,value in hash_dic.items():
            if csv_hash == value:
                print(f"for {row[0]} password is {key}")
            else:
                pass

print(hash_dic)
#print(number)

在您提到的在线站点上,您正在输入一个字符串 '9999',可能是 ASCII 或 UTF8 格式。您需要将相同的字节数组传递给 hashlib。

import hashlib
hashlib.sha256(str(9999).encode()).hexdigest()
# --> 888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05

如果您真的想将整数作为其字节表示而不是字符串传递,那么 会有所帮助。