• PyDES


    一个简单的例子:

    from pyDes import *
    data = "Please encrypt my data"
    k = des("DESCRYPT", CBC, "", pad=None, padmode=PAD_PKCS5)
    d = k.encrypt(data)
    print "Encrypted: %r" % d
    print "Decrypted: %r" % k.decrypt(d)
    assert k.decrypt(d, padmode=PAD_PKCS5) == data

    PyDES 主页:http://twhiteman.netfirms.com/des.html

    Installation

    • Extract the files from the pyDes archive.
    • Run the following command: python setup.py install

    Class initialization -------------------- pyDes.des(key, [mode], [IV], [pad], [padmode]) pyDes.triple_des(key, [mode], [IV], [pad], [padmode]) key -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes for Triple DES mode -> Optional argument for encryption type, can be either pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining) IV -> Optional Initial Value bytes, must be supplied if using CBC mode. Length must be 8 bytes. pad -> Optional argument, set the pad character (PAD_NORMAL) to use during all encrypt/decrpt operations done with this instance. padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5) to use during all encrypt/decrpt operations done with this instance.
    ommon methods
    --------------
    encrypt(data, [pad], [padmode])
    decrypt(data, [pad], [padmode])
    
    data    -> Bytes to be encrypted/decrypted
    pad     -> Optional argument. Only when using padmode of PAD_NORMAL. For
    	   encryption, adds this characters to the end of the data block when
    	   data is not a multiple of 8 bytes. For decryption, will remove the
    	   trailing characters that match this pad character from the last 8
    	   bytes of the unencrypted data block.
    padmode -> Optional argument, set the padding mode, must be one of PAD_NORMAL
    	   or PAD_PKCS5). Defaults to PAD_NORMAL.
  • 相关阅读:
    python3数据库配置,远程连接mysql服务器
    Ubuntu 16.04安装JDK
    用Python从零开始创建区块链
    理解奇异值分解SVD和潜在语义索引LSI(Latent Semantic Indexing)
    gensim介绍(翻译)
    记一次浅拷贝的错误
    Heap queue algorithm
    Python
    python列表中插入字符串使用+号
    Linux(Ubuntu)使用 sudo apt-get install 命令安装软件的目录在哪?
  • 原文地址:https://www.cnblogs.com/li-baibo/p/3175313.html
Copyright © 2020-2023  润新知