在python中使用sha-256签署私钥对

时间:2016-10-15 16:30:31

标签: python encryption-asymmetric

我想知道如何使用sha-256签署我的私钥。我已经尝试过了,但它没有用。我怎么能正确地做到这一点?顺便说一句,我使用非对称加密来加密通过网络传输的所有文件。

#!/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?")

1 个答案:

答案 0 :(得分:2)

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