SHA1withRSA签名Python版本
2021/11/23 22:10:38
本文主要是介绍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
这篇关于SHA1withRSA签名Python版本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门