python RSASHA1加密

from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA
import base64
import warnings

warnings.filterwarnings("ignore")


def get_signature(test1, test2):
    private_key = """MIICXQIBAAKBgQCVRVDNAAPMk3vHrh9KIdr3LRptz2vuq6XH5DQiZq5fPYjD6nm8
fMrL9gk+VJiANTj77Y3kN75SXjpYj2Ptx/vmsuDffZvGEMK7vHHVWbURCaZUTEbM
CfIw5/94a56R51fS5X6mgBVryqLenUy+y5VfsYcRZn50XWId/3c9T7UQdQIDAQAB
AoGAW3h+ayD3MwWtdE9fHS5h39XjvCa/HSJSFIvi5rHFaNdsV6H3t2lBXHsIbwmn
6eizYq3PpWoDVrYnSt2TfsJtuaGKFxYogPO50J91onxqHoCF1hIHED88/XTZdYDb
PeKN5SQU+nOTV+fF1SWJsXhN7CncW0K8d+hJ9fJM/M+LcoECQQDGD70GVYZdPjIi
Plu2C/WRRs2NJU6A9O5KR0/a7i0oVkzC9RX1M4VNfXhO4rD32ZZU7MardWbWE1Da
8bmmngZnAkEAwO/HfMja9Qer6h946Yv4US444GYDt2nNAe721E4UzGTQrbElma9x
buGyUeOvkt7X5aAswDAMRjmZJors8DpQwwJAUgFsM3Yv1uWMnm8RS/PxrkARlZJP
yccf7rNOFgitu9jXmZUejVLSq736lTb5LPXzb6BFtfI7LQH8ZVrWkm01mwJBAI48
d2nkPZ+k/zWD7ETpHrDijaXJL3Y5Npz1Sdzsj2K79CgIz/qEH/EpzKeYXqi9RpcP
xc4N3g6rid+jTdgwdbcCQQCLMw/BSJJsKe8Croqgo8e3mfcTelC+jiXWVm1G/HkL
GCtgsC7VRGsoyj3hMaiujCu16eg0hAMPWd15PDRvWxHj"""
    sign_str = "test1=" + "%s" % test1 + "&" + \
               "test2=" + "%s" % test2

    private_key_bytes = base64.b64decode(private_key)

    pri_key = RSA.importKey(private_key_bytes)

    signer = PKCS1_v1_5.new(pri_key, )

    hash_obj = SHA.new(sign_str.encode('utf-8'))

    signature1 = base64.b64encode(signer.sign(hash_obj))

    signature = signature1.decode('utf-8')
    print(signature)


if __name__ == '__main__':
    get_signature("test1", "test2")

你可能感兴趣的:(python,数学建模,开发语言)