RSA签名方式(华为,金立,联想,oppo,三星,支付宝)
import base64
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA, SHA256, MD5
def rsa_sign(pri_key, data, sign_type='RSA'):
"""
:param pri_key: 私钥
:param data: 待签名数据
:param sign_type: 的签名方式
:return:
"""
key = RSA.importKey(pri_key)
if sign_type == 'RSA256':
h = SHA256.new(data)
elif sign_type == 'MD5':
h = MD5.new(data.encode('utf-8'))
else:
h = SHA.new(data)
signer = PKCS1_v1_5.new(key)
signature = signer.sign(h)
return base64.b64encode(signature)
def rsa_verify(pub_key, data, sign, sign_type='RSA'):
"""
:param pub_key: 公钥
:param data: 待签名数据
:param sign: 需要验签的签名
:param sign_type: 的签名方式
:return:
"""
key = RSA.importKey(pub_key)
if sign_type == 'RSA256':
h = SHA256.new(data)
elif sign_type == 'MD5':
h = MD5.new(data.encode('utf-8'))
el

这篇博客介绍了Python中三种常见的签名验证方法:RSA用于华为、金立、联想、OPPO、三星和支付宝;MD5适用于百度、阿里九游、魅族、360和vivo;而Hmac-SHA1则在米大师(应用宝)和小米的应用场景中使用。
最低0.47元/天 解锁文章
180

被折叠的 条评论
为什么被折叠?



