rsa&md5

 

RSA公钥加密

pip3 install pycrypto


import json
import requests
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5

key = ‘xxxxx’

rsa_key = '-----BEGIN PUBLIC KEY-----\n' + key + '\n-----END PUBLIC KEY-----'

username = 'xxxxx'
passwd = 'xxxxx'

def do_rsa(rsa_key, username, passwd):
    rsakey = RSA.importKey(rsa_key)
    cipher = PKCS1_v1_5.new(rsakey)
    username = base64.b64encode(cipher.encrypt(username.encode()))
    passwd = base64.b64encode(cipher.encrypt(passwd.encode()))
    return username, passwd


account, password = do_rsa(rsa_key, username, passwd)

 

MD5加密


def my_md5(str):
    new_str = str.encode() 
    m = hashlib.md5()  
    m.update(new_str)  
    return m.hexdigest()  

 

你可能感兴趣的:(python)