pwdCry.py 786 Bytes
# -*- coding: utf-8 -*-

# @Time    : 2021/7/20 10:36
# @Author  : Ljq
# @File    : pwdCry.py
# @Software: PyCharm

"""

"""

import base64
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Crypto.PublicKey import RSA

def pwdCry(string):
    public_key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCgN7kda5L4ztOUquoHjubQIEyqBpjpaYeq+DBKXA3JNOZsMjGwLGVqfCwQg3HHAGTaWnxsp5gjmh0tSziJFgQf2u45TqA2UObOvklRhbWr56QoTNsjm72wZoSOlUzW3xHi/6PocHdy/7bMOiDf6fmYhFBZdRleX6tCAp7w6DsdbQIDAQAB'
    key = '-----BEGIN PUBLIC KEY-----\n' + public_key + '\n-----END PUBLIC KEY-----'
    rsakey = RSA.importKey(key)
    cipher = Cipher_pksc1_v1_5.new(rsakey)
    encrypt_text = cipher.encrypt(string.encode("utf-8"))
    cipher_text = base64.b64encode(encrypt_text)
    return cipher_text.decode()