zoukankan      html  css  js  c++  java
  • 项目里用到的python知识点


    1 ini文件处理
    创建ini文件
    config = configparser.ConfigParser()
    config.read(AUTH_STATUS_FILE)
    config.add_section("authorization")
    config.set("authorization", "file_status", "normal")    
    config.set("authorization", "auth_status", "normal")
    config.set("authorization", "remain_time", "100")
    config.add_section("systime")
    config.set("systime", "file_status", "normal")
    config.set("systime", "time_status", "normal")
    config.write(open(AUTH_STATUS_FILE, "w"))  
    从字符串解析ini文件
    config = configparser.ConfigParser(allow_no_value=True)
    config.read_string(auth_info.decode())
    auth_id = config.get('auth_id', 'id')
    start_time = config.get('auth_date', 'start')
    end_time = config.get('auth_date', 'end')

    2 时间转换与比较
    tStart = time.strptime(start_time, "%Y%m%d%H%M%S")
    tEnd = time.strptime(end_time, "%Y%m%d%H%M%S")
    dStart = datetime.datetime(* tStart[:6])
    dEnd = datetime.datetime(* tEnd[:6])
    dCurrent = datetime.datetime.now()

    3 文件读写
    with open(FACEMP_AUTH_OUT, 'r') as f:
        auth_crypt_info = f.read()
        
    4 把python源码编译为pyc
    py_compile.compile('./facemp_check.py')

    5 生成rsa公私钥对
    from M2Crypto import RSA,BIO
    rsa = RSA.gen_key(1024, 3, lambda *agr:None)
    rsa.save_pub_key('facemp_pub.key')
    rsa.save_key('facemp_pri.key', None)

    6 私钥加密
    privkey = M2Crypto.RSA.load_key('facemp_pri.key')
    encrypted = privkey.private_encrypt(message, M2Crypto.RSA.pkcs1_padding)

    7 公钥解密
    pubkey = M2Crypto.RSA.load_pub_key(FACEMP_PUB_KEY)
    auth_info = pubkey.public_decrypt(auth_crypt_info, M2Crypto.RSA.pkcs1_padding)   

     

  • 相关阅读:
    Vue.js
    Spark Streaming自定义Receiver
    Hive UDF函数
    HBase表预分区与压缩
    Hive映射HBase表的几种方式
    Spark源码阅读之存储体系--存储体系概述与shuffle服务
    Spark Streaming实时写入数据到HBase
    基于Spark的用户行为路径分析
    Spark Streaming消费Kafka Direct方式数据零丢失实现
    CountDownLatch如何使用
  • 原文地址:https://www.cnblogs.com/mingzhang/p/7543438.html
Copyright © 2011-2022 走看看