Diana Selena
Diana Selena

Reputation: 21

Sign private key pair with sha-256 in python

I want to know how can I sign my private key with sha-256. I already tried it, but it didn't work.. how can I do it properly? by the way I'm using a asymmetric encryption to encrypt all files that are transferred via network.

#!/usr/bin/python
    from Crypto.PublicKey import RSA
    from OpenSSL import SSL
    import socket
    import hashlib
    import os

    #load public key
    def publicKey():
        with open('public_key.key', 'r') as public_file:
            public_key = RSA.importKey(public_file.read())

    #load private key
    def privateKey():
        with open('private_key.key', 'r') as private_file:
            private_key = RSA.importKey(private_file.read())

    if __name__ == '__main__':
        txt = input("what do you want to do?")

Upvotes: 1

Views: 2630

Answers (1)

Rocky Chen
Rocky Chen

Reputation: 468

signature = hmac.new(key=private_key, message, digestmod=hashlib.sha256).digest()

Upvotes: 2

Related Questions