三联蟒的实现

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以编程方式最小化JInternalFrame?   java使用JsonPath将不均匀列表提取为类型化对象   spring如何将java/resources文件获取到InputStream?   Java逻辑错误并不总是存在   java Firebase,更新特定字段   Java stream groupby并同时加入以进行csv导出   java安卓:如果出现任何声音,监听器将录制声音   java如何从多个文件中轮询最后修改的文件并发送到apache camel中的目标端点?   java是否返回多个比较器?   JavaBean IO:Date MMM在CAPS中不解析   当JButton从另一个类单击时,java正在更新JLabel   基类中子类的Java泛型初始化   jakarta ee Java ee制作一个以毫秒为间隔的计时器来发送数据包   json Windows Azure日期格式转换为Java日期