SHA1withRSA签名Python版本
from Crypto.PublicKey import RSA from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA1 import base64 import time import warnings warnings.filterwarnings("ignore") class GetToken(object): def __init__(self): self.timestamp = str(int(time.time())) self.ver = "0" self.client_id = "10088" self.user_id = "74118879715" def get_token(self): 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''' content = "{0}|{1}|{2}|{3}".format(self.ver, self.client_id, self.user_id, self.timestamp) print(content) private_key_bytes = base64.b64decode(private_key) pri_key = RSA.importKey(private_key_bytes) signer = PKCS1_v1_5.new(pri_key, ) hash_obj = SHA1.new(content.encode('utf-8')) signature1 = base64.b64encode(signer.sign(hash_obj)) signature = signature1.decode('utf-8') print(signature) token = "{0}|{1}|{2}|{3}|{4}".format(self.ver, self.client_id, self.user_id, self.timestamp, signature) return token