错误哈希+盐密码
Error Hashing + Salt password
你能帮我解决这个问题吗:
TypeError: can't concat bytes to str
我正在尝试安全地存储哈希 + salt 密码。
我认为问题是我的盐是一个字节对象。
如何将其转换为字符串?
或者有更好的散列方法吗?
import base64
import hashlib
import os
def getDigest(password, salt=None):
if not salt:
salt = base64.b64encode(os.urandom(32))
digest = hashlib.sha256(salt + password).hexdigest()
return salt, digest
def isPassword(password, salt, digest):
return getDigest(password, salt)[1] == digest
print(getDigest('batman'))
你可以在 salt
编码后做 salt = salt.decode("utf-8")
将其转换为字符串。
你能帮我解决这个问题吗:
TypeError: can't concat bytes to str
我正在尝试安全地存储哈希 + salt 密码。
我认为问题是我的盐是一个字节对象。
如何将其转换为字符串?
或者有更好的散列方法吗?
import base64
import hashlib
import os
def getDigest(password, salt=None):
if not salt:
salt = base64.b64encode(os.urandom(32))
digest = hashlib.sha256(salt + password).hexdigest()
return salt, digest
def isPassword(password, salt, digest):
return getDigest(password, salt)[1] == digest
print(getDigest('batman'))
你可以在 salt
编码后做 salt = salt.decode("utf-8")
将其转换为字符串。