在 Python 中使用 salt 加密密码时出错

Getting error while encrypting the password using salt in Python

我在使用 Python 加密密码时遇到错误。我在下面解释错误。

Error:

Traceback (most recent call last):
  File "password.py", line 60, in <module>
    hashed_password = hashlib.sha512(sword + salt).hexdigest()
TypeError: cannot concatenate 'str' and 'list' objects

我的代码如下。

import hashlib
value = "2Y7xk5vrs5DeCcSdinRVKQ=="
salt = value.split()
sword = "subhra1234"
hashed_password = hashlib.sha512(sword + salt).hexdigest()
print(hashed_password)

这里我需要使用自己的盐值并尝试加密密码。请帮助解决此错误。

就像@MosesKoledoye 说的,你不需要在 salt 上调用 split:

import hashlib
salt = "2Y7xk5vrs5DeCcSdinRVKQ=="
sword = "subhra1234"
hashed_password = hashlib.sha512(sword + salt).hexdigest()
print(hashed_password)