Bcrypt ValueError:使用自定义盐时盐无效
我正在开发一个需要散列的项目。问题是我想创建一个自定义哈希(使用添加非英语字符和符号的程序生成)。当使用简单的字符串进行测试时,我收到错误 ValueError: Invalid salt
。我尝试过的代码:
def test():
password = b"pass123"
password2 = input("Enter password: ")
bpassword2 = password2.encode('utf-8')
salt = b"test"
hashed = bcrypt.hashpw(password, salt)
print(hashed)
hash2 = bcrypt.hashpw(bpassword2, bcrypt.gensalt())
print(hash2)
test()
这会返回错误。我也尝试过:
def test():
password = b"pass123"
password2 = input("Enter password: ")
bpassword2 = password2.encode('utf-8')
salt = "test"
hashed = bcrypt.hashpw(password, salt)
print(hashed)
hash2 = bcrypt.hashpw(bpassword2, bcrypt.gensalt())
print(hash2)
test()
但是这会返回错误TypeError:Unicode-objects必须在散列之前进行编码
。老实说,我不知道该怎么做,如果这是一个非常简单的修复,那么我很抱歉。
I'm working on a project where hashing is required. The problem is that I want to create a custom hash (generated with a program that would add non-english characters and symbols). When testing this with a simple string I get the error ValueError: Invalid salt
. The code I tried:
def test():
password = b"pass123"
password2 = input("Enter password: ")
bpassword2 = password2.encode('utf-8')
salt = b"test"
hashed = bcrypt.hashpw(password, salt)
print(hashed)
hash2 = bcrypt.hashpw(bpassword2, bcrypt.gensalt())
print(hash2)
test()
This returns the error. I've also tried:
def test():
password = b"pass123"
password2 = input("Enter password: ")
bpassword2 = password2.encode('utf-8')
salt = "test"
hashed = bcrypt.hashpw(password, salt)
print(hashed)
hash2 = bcrypt.hashpw(bpassword2, bcrypt.gensalt())
print(hash2)
test()
However this returns the error TypeError: Unicode-objects must be encoded before hashing
. I honestly don't know what to do and if this is a really simple fix then I'm sorry ????.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 bcrypt.hashsalt 期望盐的长度 > 16 个字符。这是该方法的源代码:
The issue is that the
bcrypt.hashsalt
expects the salt to be of length > 16 characters. here is the source code of the method: