【问题标题】:python md5 encryption using the update function with a variablepython md5加密使用带有变量的更新函数
【发布时间】:2014-06-08 13:15:43
【问题描述】:

我有:

import hashlib
md5_object = hashlib.md5()
string = input("Enter a string to encrypt: ")
md5_object.update(b,string)
secret_code = md5_object.hexdigest()

如何将字符串变量传递给update() 函数?

【问题讨论】:

标签: python encryption md5


【解决方案1】:

只需将您的字符串编码为 UTF-8:

import hashlib
md5_object = hashlib.md5()
string = input("Enter a string to encrypt: ")
md5_object.update(string.encode("utf-8"))
secret_code = md5_object.hexdigest()

否则会报这个错误:

TypeError: Unicode-objects must be encoded before hashing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2023-03-27
    • 2014-06-25
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多