OverflowError: 128 bytes needed for message, but there is only space for 117
蓝色小桌子 2019-10-28 01:47:06 接口测试,有一个入参是要加密的,需求是这样的:一json串明文的,先进行base64编码,再用xx.pfx格式的私钥和私钥密码进行RSA加密,即为请求参数的值
我的实现方式是:
1.openssl pkcs12 -in cheyunlong_pri.pfx -nocerts -nodes -out private_pc.key #从xxx.pfx中提取密钥对
2.openssl rsa -in private_pc.key -out private.pem #从密钥对中提取私钥(头部格式:-----BEGIN RSA PUBLIC KEY-----)
3.openssl rsa -in private.pem -RSAPublicKey_out -out public.pem #从密钥对提取公钥(头部格式:-----BEGIN RSA PRIVATE KEY-----)
python代码如下:
import base64,rsa
privatePath = r"F:\testing\idelements\private.pem"
def encryption(data):
print("raw data -->", data)
mes = base64.b64encode(data.encode('utf-8'))
print("after base64 en", mes)
with open(privatePath,'r') as f:
privKey = rsa.PrivateKey.load_pkcs1(f.read().encode())
rsa.encrypt(mes,privKey)
return data
rawdata = {
"aa_id": "8004000084",
"bb_id": "8004000084",
"trans_id": "14744392884941234",
"trade_date": "20160921142808",
"id_card": "431224198805042030",
"id_holder": "wendy",
"yxqqsrq": "20190101",
"yxqjzrq": "20201010",
"industry_type": "A1"}
x = encryption(str(rawdata))
print("x", x)
运行总是出现:OverflowError: 128 bytes needed for message, but there is only space for 117 这个错误,百度上居然查不到,有遇到过此问题的童鞋吗?肯请帮助指教!