ECDSA не могу подписать сообщение - Python

Формулировка задачи:

Всем привет, затык в ecdsa
import ecdsa
 
    # создаю публичный и приватный ключ
    def generate_key(self):
        generate_key = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1)
        public_key = generate_key.get_verifying_key()
        private_key = binascii.hexlify(generate_key.to_string()).decode()
        public_key = public_key.to_string().hex()
        return (private_key, public_key)
print(privat_key) bd25620fe024006abe4fcedf6e62a9dda2844126c516c8ec37e00797bc384130
    # подписываю некое сообщение string
    def generate_sig(self, prkey, msg):
        prkey = binascii.unhexlify(prkey)
        private_key = ecdsa.SigningKey.from_string(prkey,curve=ecdsa.SECP256k1)
        sign_msg = private_key.sign(msg) # <<-здесь ошибка
        return private_key
C:\Users\Egor\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/Egor/PycharmProjects/untitled/main.py * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) [2018-04-04 02:32:44,242] ERROR in app: Exception on /openwallet [POST] Traceback (most recent call last): File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\flask\app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\flask\app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\flask\_compat.py", line 33, in reraise raise value File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\flask\app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:/Users/Egor/PycharmProjects/untitled/main.py", line 79, in open_and_varify_file return send_atom(file_bytes) File "C:/Users/Egor/PycharmProjects/untitled/main.py", line 128, in send_atom msg['sign'] = wallet.generate_sig(file_bytes['privatkey_clear'],str(msg)) File "C:\Users\Egor\PycharmProjects\untitled\wallet.py", line 73, in generate_sig sign_msg = private_key.sign(msg).encode('utf-8') File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\ecdsa\keys.py", line 254, in sign h = hashfunc(data).digest() TypeError: Unicode-objects must be encoded before hashing 127.0.0.1 - - [04/Apr/2018 02:32:44] "POST /openwallet HTTP/1.1" 500 -

Код к задаче: «ECDSA не могу подписать сообщение - Python»

textual
File "C:\Users\Egor\PycharmProjects\untitled\wallet.py", line 73, in generate_sig
sign_msg = private_key.sign(msg).encode('utf-8')
File "C:\Users\Egor\PycharmProjects\untitled\venv\lib\site-packages\ecdsa\keys.py", line 254, in sign
h = hashfunc(data).digest()
TypeError: Unicode-objects must be encoded before hashing
Эта работа вам не подошла?

Вы всегда можете заказать любую учебную работу у наших авторов от 20 руб.

7   голосов, оценка 4.286 из 5


СДЕЛАЙТЕ РЕПОСТ