d.j.bernstein对salsa20和xsalsa20的nacl实现的绑定
salsa20的Python项目详细描述
D.J.Bernstein(摘自Libs钠)对SALSA20和XSALSA20 NaCl实施的绑定。
与Python2.6、2.7和3.3兼容。
库在每次导入时执行自检。
安装
pip install salsa20
用法
def Salsa20_keystream(length, nonce, key) def Salsa20_xor(message, nonce, key) def XSalsa20_keystream(length, nonce, key) def XSalsa20_xor(message, nonce, key)
使用[X]Salsa20_keystream生成所需长度的密钥流,或通过[X]Salsa20_xor明文或密文将其与密钥流异或。
作为流密码,[X]Salsa20_xor同时进行加密和解密。
所有值都必须是二进制字符串(python 2上的str,python 3上的bytes)
示例
>>> from salsa20 import XSalsa20_xor >>> from os import urandom >>> IV = urandom(24) >>> KEY = b'*secret**secret**secret**secret*' >>> ciphertext = XSalsa20_xor(b"IT'S A YELLOW SUBMARINE", IV, KEY) >>> print(XSalsa20_xor(ciphertext, IV, KEY).decode()) IT'S A YELLOW SUBMARINE