我想使用rsa私钥签名,并使用sha-256对其进行编码 但我总是有这个错误
TypeError: Unicode-objects must be encoded before hashing
以下是代码段:
private_key = rsa.PrivateKey.load_pkcs1(open('private.pem', 'rb').read())
signature = rsa.sign(sign, private_key, 'SHA-256')
你能帮我解决这个问题吗?
答案 0 :(得分:1)
编码为“utf-8”应该适合你。
private_key = rsa.PrivateKey.load_pkcs1(open('private_key.pem', 'rb').read())
signature = rsa.sign(sign.encode("utf-8"), private_key, 'SHA-256')