1. pip install pycryptodome
2.
def encropy():
import base64
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Crypto.PublicKey import RSA
def encrpt(password, public_key):
rsakey = RSA.importKey(public_key)
cipher = Cipher_pksc1_v1_5.new(rsakey)
cipher_text = base64.b64encode(cipher.encrypt(password.encode()))
return cipher_text.decode()
# key是公钥,需要修改成自己的之后再进行加密
key = 'publickey'
public_key = '-----BEGIN PUBLIC KEY-----\n' + key + '\n-----END PUBLIC KEY-----'
password = encrpt('mykey', public_key)
print('password:', password)
注意,如果出现无法导入包,需要卸载pycrypt 重新安装pycryptodome