python python3 RSA加密

2019-10-16 11:11:38 浏览数 (1)

代码语言:javascript复制
#!/usr/bin/env python
# coding=utf-8
# author: wz
# mail: 277215243@qq.com
# datetime:2019/10/15 12:42 PM
# web: https://www.bthlt.com

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

pubkey = """-----BEGIN RSA PUBLIC KEY-----n
加密码
n-----END RSA PUBLIC KEY-----n"""
messages = [
    'userid=test1',
    'userid=test2',
    'userid=test3'
]
for message in messages:
    rsakey = RSA.importKey(pubkey)  
    cipher_rsa = PKCS1_v1_5.new(rsakey)
    message = message.encode(encoding="utf-8")
    cryptedMessage = cipher_rsa.encrypt(message)
    encry_message = base64.b64encode(cryptedMessage)
    print("https://h5.test.qq.com/index?&data={0}".format(encry_message.decode()))

0 人点赞