0
암호를 해시하려고하는데 성공하지 못했습니다. 이것은 코드입니다.Hashlib unicode error
from hashlib import sha1 as sha_constructor
import random
def generate_sha1(string, salt=None):
if not isinstance(string, (str, str)):
string = str(string)
if isinstance(string, str):
string = string.encode("utf-8")
if not salt:
salt = sha_constructor(str(random.random())).hexdigest()[:5]
hash = sha_constructor(salt + string).hexdigest()
return salt, hash
a = generate_sha1('12345')
print(a)
이 오류가 발생합니다.
TypeError: Unicode-objects must be encoded before hashing
내가 뭘 잘못하고 있니?
파이썬 3은 유니 코드를 지원하지 않습니다. 파이썬 3.4를 사용하고 있습니다 – ajkumar25
올바른 태그를 사용하십시오. 내 대답을 업데이트했습니다. –