rsa非对称加密

rsa非对称加密

#-*-coding:utf-8-*-
#@author    :vict
#@Time      :2021-09-17 16:12
#@File      :newEntryOverClient
#@software  :PyCharm
import json
import requests
import rsatool
import time
import base64

if __name__ == '__main__':
    senddict = {}
    senddict['Id'] = '018001333210917163333001'
    senddict['time'] = time.strftime("%Y%m%d%H%M%S", time.localtime())
    senddict['devNo'] = '112'
    senddict['obuId'] = '111111'
    senddict['vehPlate'] = '云SAD268'
    senddict['color'] = 0
    senddict['vehClass'] = 1
    senddict['weight'] = 2000
    senddict['aixs'] = 2
    senddict['speed'] = 120
    senddict['maxWeight'] = 9999
    senddict['overLimit'] = 9999
    senddict['overLimitRate'] = 0
    senddict['vehLen'] = 100
    senddict['vehWide'] = 100
    senddict['vehHight'] = 100
    senddict['isDJYS'] = 0
    senddict['isRelease'] = 1
    senddict['certNo'] = "32392138502131"
    senddict['isBlackvehicle'] = 2

    rsatool = rsatool.RsaTool('rsa_public_key.pem', 'rsa_private_key.pem')
    bts_str = (json.dumps(senddict)).encode()
    crypto_bytes = rsatool.rsa_public_encrypt(bts_str)
    cipher_text = base64.b64encode(crypto_bytes)
    print(cipher_text)
    #rsa非对称加密
    ret = requests.post("http://127.0.0.1:8765/security/WeighingLane/RealTimeWeighingInfo", data=crypto_bytes)
    print(ret.status_code)
    print(type(ret.content))
    print(base64.b64encode(ret.content))
    d_crypto_bytes = rsatool.rsa_private_decrypt(ret.content)
    print(d_crypto_bytes)
    #无加密
    ret = requests.post("http://127.0.0.1:8765/WeighingLane/RealTimeWeighingInfo", data=bts_str)
    print(ret.status_code)
    print(type(ret.content))
posted @ 2021-11-12 10:59  不知云深处  阅读(69)  评论(0编辑  收藏  举报