zoukankan      html  css  js  c++  java
  • python---rsa加密根据指数和模生成加密参数模板

    代码+注释

    from cryptography.hazmat.backends import default_backend
    from cryptography.hazmat.primitives.asymmetric import rsa
    from cryptography.hazmat.primitives.asymmetric import padding
    import base64
    
    """
    另种rsa加密
    """
    
    
    def data_encrypt(text):
        """
            RSA 加密
        :param text:    加密前内容
        :return:        加密后内容
        """
        # 判断系统,加载指定模块
        public_exponent = int("010001",16)  #指数
        print(public_exponent)
        public_modulus=int('B23322F080BD5876C0735D585D25C7BC409F637237B07744D27FBF39FB100ABE59DF380EA6BFCDF28C286E7A0CD95BE87F6099F8F39B0E97D9782C3D33FCFB80D43D2F22A9D9417ECFD1A0B8421DEE1CD4B323E8078336E77419A97F94E60A90CA06551202F63819FC8E73425F06ECA4C05BBF8CA32366240A6C36CA61D85019',16) #模
        # content = 'leadeon' + text + time.strftime("%Y%m%d%H%M%S", time.localtime())
        content = text
        max_length = 117
        # public_key = serialization.load_pem_public_key(key, backend=default_backend())
        public_key = rsa.RSAPublicNumbers(public_exponent, public_modulus).public_key(default_backend())
        data = b''
        for i in range(0, len(content), max_length):
            data += public_key.encrypt(content[i: i + max_length].encode(),
                                       padding.PKCS1v15())
        data = base64.b64encode(data).decode()
        return data
    
    
  • 相关阅读:
    MongoDB 学习笔记之 Aggregation Pipeline实战实现inner join
    MongoDB 学习笔记之 Aggregation Pipeline
    Shiro学习(3)授权
    Shiro学习(2)身份验证
    Shiro学习(1)简介
    redis常用命令建议
    Redis入门
    导出EXCEL(带数据)
    导出文件中文乱码处理
    poi之Excel上传
  • 原文地址:https://www.cnblogs.com/pythonywy/p/13458444.html
Copyright © 2011-2022 走看看