python python3 RSA加密

葫芦的运维日志

下一篇 搜索 上一篇

2019/10/15 13:03


#!/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()))

葫芦的运维日志

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2019 王梓 赞助联系方式 陕ICP备17005322号