简体   繁体   中英

How to sign a message in Python without getting an error?

The error is:

TypeError:This is not a private key

I have tried this:

def sign_transaction(self):
    private_key = RSA.importKey(binascii.unhexlify(self.sender_private_key))
    signer = PKCS1_v1_5.new(private_key)
    h = SHA.new(str(self.to_dict()).encode('utf8'))
    return binascii.hexlify(signer.sign(h)).decode('ascii')
def verify_transaction_signature(self, sender_address, signature, transaction):
    public_key = RSA.importKey(binascii.unhexlify(sender_address))
    verifier = PKCS1_v1_5.new(public_key)
    h = SHA.new(str(transaction).encode('utf8'))
    return verifier.verify(h, binascii.unhexlify(signature))

I'm using Python 3.8.

My problem was in my database I was sending private key to public key column. So I was trying to sign my transaction with public key instead of my private key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM