pychickenticket密码工作的快速模块
ct-crypto的Python项目详细描述
ct_crypto-pychickentiket密码模块
文档
encrypt(data, password)
使用 给定密码,并返回解密数据。
如果使用非默认长度参数解密数据, 加密必须使用相同的参数完成。
Parameters
-----------
data: bytes
The binary data to encrypt.
password: str
The password to encrypt the data with.
Returns
--------
bytes
Bytes object containing the decrypted data.
Raises
-------
TypeError
If argument datatypes are incorrect
ValueError
If argument length is incorrect
RuntimeError
If data decryption authentication fails
MemoryError
If key derivation or decryption fails
decrypt(data, password)
使用 给定密码,并返回解密数据。
如果使用非默认长度参数解密数据, 加密必须使用相同的参数完成。
Parameters
-----------
data: bytes
The binary data to encrypt.
password: str
The password to encrypt the data with.
Returns
--------
bytes
Bytes object containing the decrypted data.
Raises
-------
TypeError
If argument datatypes are incorrect
ValueError
If argument length is incorrect
RuntimeError
If data decryption authentication fails
MemoryError
If key derivation or decryption fails
get_def(def_index)
获取索引并返回lib钠的值 与该索引关联的常量。
下面的索引->;常量表
0 -> crypto_box_SEEDBYTES
1 -> crypto_pwhash_SALTBYTES
2 -> crypto_pwhash_PASSWD_MIN
3 -> crypto_pwhash_PASSWD_MAX
4 -> crypto_pwhash_BYTES_MIN
5 -> crypto_pwhash_BYTES_MAX
6 -> crypto_pwhash_OPSLIMIT_MIN
7 -> crypto_pwhash_OPSLIMIT_MAX
8 -> crypto_pwhash_MEMLIMIT_MIN
9 -> crypto_pwhash_MEMLIMIT_MAX
10 -> crypto_secretbox_KEYBYTES
11 -> crypto_secretbox_MACBYTES
12 -> crypto_secretbox_NONCEBYTES
13 -> crypto_secretbox_MESSAGEBYTES_MAX
Parameters
-----------
def_index: int
Index of the constant you want to fetch.
Returns
--------
int
Value of the specified constant
Raises
-------
KeyError
If the index has no associated constant
genkey(key_size)
生成长度为key_size
字节的安全密钥。
Parameters
-----------
key_size: int
Determines the length of the generated key
Returns
--------
bytes
The generated key
Raises
-------
ValueError
If key size is below 32
random_bytes(buffer_size)
生成加密安全的随机字节,最多为buffer_size
。
如果buffer_size
为0,则返回None
。
Parameters
-----------
buffer_size: int
Determines the size of the buffer used to hold the random bytes.
Returns
--------
bytes
Buffer of random bytes
hexdigest(data)
返回给定值的hexDigest。
如果data
为空,则返回None
。
Parameters
-----------
data: bytes
Bytes object to calculate the hexdigest for.
Returns
--------
str
The hexdigest in string format.
Raises
-------
MemoryError
If memory could not be allocated for the hex buffer
derive_key(password, salt, key_size)
使用argon2id算法从密码和哈希中派生密钥。
生成的密钥长度为key_size
字节。
如果任何参数为空,则返回None
。
Parameters
-----------
password: str
Password to use for key derivation.
salt: bytes
Bytes object storing the salt to use for key derivation.
key_size: int
Determines size of the generated key.
Returns
--------
bytes
The secret key.
Raises
-------
MemoryError
If memory could not be allocated for derivation.
encrypt_secret(data, key, nonce)
使用key
和nonce
加密data
,使用
用于加密和poly1305的xsalsa20流密码
用于身份验证的Mac。
如果任何参数为空,则返回None
。
Parameters
-----------
data: bytes
The data to encrypt.
key: bytes
The secret key to use for encryption.
nonce: bytes
The nonce to use for encryption.
Returns
--------
bytes
The encrypted data, signed with the MAC tag.
Raises
-------
MemoryError
If memory could not be allocated for encryption
RuntimeError
If encryption fails
decrypt_secret(data, key, nonce)
使用key
和nonce
解密data
,使用
用于加密和poly1305的xsalsa20流密码
用于身份验证的Mac。
如果任何参数为空,则返回None
。
Parameters
-----------
data: bytes
The data to decrypt.
key: bytes
The secret key to use for decryption.
nonce: bytes
The nonce to use for decryption.
Returns
--------
bytes
The decrypted data.
Raises
-------
MemoryError
If memory could not be allocated for decryption
RuntimeError
If decryption authentication fails