zoukankan      html  css  js  c++  java
  • python3进行3des的加密解密


    #
    秘钥长度正常24位,16位补齐第一个八位 import pyDes import base64 print('=======key1=======') keys='1234567890123456' k = pyDes.triple_des(keys,pyDes.ECB, "",pad=None, padmode=pyDes.PAD_PKCS5) d = k.encrypt("137613") print(base64.b64encode(d)) e = k.decrypt(d) print(e) print('=======key2=======') keys2='123456789012345612345678' k2 = pyDes.triple_des(keys2,pyDes.ECB, "",pad=None, padmode=pyDes.PAD_PKCS5) d2 = k2.encrypt("137613") print(base64.b64encode(d2)) e2 = k.decrypt(d2) print(e2) print('=======key3=======') keys3='123456789090909090909090' k3 = pyDes.triple_des(keys3,pyDes.ECB, "",pad=None, padmode=pyDes.PAD_PKCS5) d3 = k3.encrypt("137613") print(base64.b64encode(d3)) e3 = k3.decrypt(d3) print(e3) #J01CKsP9aIcsXbqFmSYlbw==
    #秘钥长度不正常10位,通过空字符来补齐,先加密再解密
    import pyDes
    import base64
    
    keys='1234567890!'+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)
    k = pyDes.triple_des(keys,pyDes.ECB, "" ,pad=None, padmode=pyDes.PAD_PKCS5)
    d = k.encrypt("17862299")
    print(d)
    print(base64.b64encode(d))
    
    e = k.decrypt(d)
    print(e)
    #jnjOe8CdrxROEwvCu58T4w==
    
    #秘钥长度不正常10位,通过空字符来补齐,直接解密
    import pyDes
    import base64
    
    keys='1234567890'+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)
    k = pyDes.triple_des(keys,pyDes.ECB, "" ,pad=None, padmode=pyDes.PAD_PKCS5)
    d='zzz3jP2U4ntEB+ECeykj6w=='
    d=base64.b64decode(d)
    e = k.decrypt(d)
    print(e)
  • 相关阅读:
    uniapp获取mac地址,ip地址
    uni-app实现扫码
    uniapp常用提示框uni.showToast(OBJECT)
    cookie和session
    JDBC程序执行步骤--repeat
    maven项目中Spring整合Shiro配置文件(示例)
    Could not find action or result: /bos_fore/order_add.action
    datagrid的行编辑
    使用Nexus搭建maven私服二三事
    创建maven-web项目时找不到archetype
  • 原文地址:https://www.cnblogs.com/castlevania/p/8624884.html
Copyright © 2011-2022 走看看