python基于rsa公钥加密范例

加密方法:

import base64
import rsa
from datetime import datetime
from Crypto.PublicKey import RSA


# 公钥加密
def encryptPassword(password, publicKeyStr):
    # 1、base64解码
    publicKeyBytes = base64.b64decode(publicKeyStr.encode())
    # 3、生成publicKey对象
    key = RSA.import_key(publicKeyBytes)
    # 4、对原密码加密
    encryptPassword = rsa.encrypt(password.encode(), key)
    return base64.b64encode(encryptPassword).decode()

你可能感兴趣的:(python基于rsa公钥加密范例)