三联蟒的实现

TripleSec的Python项目详细描述


Build StatusCoverage StatusPyPi versionPyPi downloads

TripleSec库的python端口。另请参见jsimplementation

与Python2.7和3.6+兼容。

安装

pip install TripleSec

用法

实例化一个triplesec.TripleSec(key=None)对象,有或没有键(如果省略,则每次使用时都必须指定),然后使用encrypt(message, key=None)decrypt(ciphertext, key=None)方法。

所有值都必须是二进制字符串(python 2上的str,python 3上的bytes

快捷方式

(未知的)函数encryptdecrypt在模块级公开。

命令行工具

triplesec提供了一个triplesec命令行工具来加密和解密来自终端的消息。

以下是帮助:

Command-line TripleSec encryption-decryption tool

usage: triplesec [-h] [-b | --hex] [-k KEY] {enc|dec} [data]

positional arguments:
  {enc|dec}          enc: encrypt and sign a message with TripleSec; by
                     default output a hex encoded ciphertext (see -b and
                     --hex) -- dec: decrypt and verify a TripleSec ciphertext
  data               the TripleSec message or ciphertext; if not specified it
                     will be read from stdin; by default ciphertexts will be
                     considered hex encoded (see -b and --hex)

optional arguments:
  -h, --help         show this help message and exit
  -b, --binary       consider all input (key, plaintext, ciphertext) to be
                     plain binary data and output everything as binary data -
                     this turns off smart decoding/encoding - if you pipe
                     data, you should use this
  --hex              consider all input (key, plaintext, ciphertext) to be hex
                     encoded; hex encode all output
  -k KEY, --key KEY  the TripleSec key; if not specified will check the
                     TRIPLESEC_KEY env variable, then prompt the user for it
  --compatibility    Use Keccak instead of SHA3 for the second MAC and reverse
                     endianness of Salsa20 in version 1. Only effective in
                     versions before 4.

0.5的变化

对于消息身份验证,triplesec规范在版本1到3中使用keccak sha3建议函数,但是在一段时间内,这个库使用了标准化的sha3-512函数。因此,默认情况下,版本1到3的python实现与javascript和golang实现不兼容。 从版本4开始,规范将只使用标准化的sha3-512函数(例如,在python中通过hashlib提供),python、javascript和golang实现将是兼容的。

如果您想在版本1到3中使用keccak(从而实现与node和go包的兼容性),您可以将compatibility=true传递到encryptdecrypt,或者在命令行中传递,如上面一节中所述。

此外,未指定版本的加密现在将默认使用版本4,这与以前的版本不兼容。

示例

>>> import triplesec
>>> x = triplesec.encrypt(b"IT'S A YELLOW SUBMARINE", b'* password *')
>>> print(triplesec.decrypt(x, b'* password *').decode())
IT'S A YELLOW SUBMARINE
>>> from triplesec import TripleSec
>>> T = TripleSec(b'* password *')
>>> x = T.encrypt(b"IT'S A YELLOW SUBMARINE")
>>> print(T.decrypt(x).decode())
IT'S A YELLOW SUBMARINE

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何使用Java解析Html并将结果作为字符串   java我的switch语句有点问题   java在注册后为新用户生成唯一的用户ID   Java 8 lambda表达式字节码一致性   Java应用程序的playframework类型安全控制台配置   java将mxGraph导出到SVG(或任何类型的图像)   业务逻辑之前的java执行方法   LinkedList输出null的Java实现   java需要帮助检查值是否为1   java Delaunay三角形点连通性?   使用setImageResource的java相对路径   java获取方法所消耗的时间   正则表达式当字符串不匹配时,为什么javagrok返回最后一次成功匹配?   java在Spring批处理作业之后触发Spring集成出站适配器   集合Java按降序遍历映射集,返回所需的输出   代表设计模式在Swagger生成代码中的java意义?   如何使用Java代码将Sql Server的数据(行)实时复制到MySql中?