A friendly cryptographic primitives library.
Project description
xycrypto
Installation
Require Python 3.6+.
pip install -U xycrypto
Ciphers
The xycrypto
provides simple and elegant interfaces for ciphers.
The cryptography components for ciphers we support:
- Available stream cipher:
ChaCha20
,RC4
. - Available block cipher:
AES
,Blowfish
,Camellia
,CAST5
,DES
,IDEA
,SEED
,TripleDES
. - Available mode:
ECB
,CBC
,CFB
,OFB
,CTR
. - Available padding:
PKCS7
,ANSIX923
,ISO10126
.
Usage
Firstly, you should import the cipher class from the package xycrypto.ciphers
. The cipher class follows the following naming conventions:
- For stream cipher,
<cipher_name>
. - For block cipher,
<cipher_name>_<mode>
.
>>> from xycrypto.ciphers import AES_CBC
Secondly, you should create the instance of the cipher class. In this case, you should provide some arguments:
- key for all ciphers.
- iv for block cipher in
ECB
,CBC
,OFB
,CFB
mode. - nonce for block cipher in
CTR
mode. - padding for block cipher in
ECB
,CBC
mode.
# The len(key) is 16 bytes for AES-128, you can use 32 bytes key for AES-256.
>>> key = b'0123456789abcdef'
# Note len(iv) should be equal to AES_CBC.block_size.
>>> iv = b'0123456789abcdef'
# We use PKCS7 padding.
>>> cipher = AES_CBC(key, iv=iv, padding='PKCS7')
Finally, call encrypt
or decrypt
method to encrypt or decrypt data respectively.
>>> plaintext = b'Welcome to xycrypto!'
>>> ciphertext = cipher.encrypt(plaintext)
>>> ciphertext
b'3\x0f\xad\xa6\x17\xc4}\xb9\t\x17\xf8\xae\xbb\xa2t\xb9o\xf2\xf6\x16\t\x0803\xaci\x0c\x19q\x9d\xa3O'
>>> cipher.decrypt(ciphertext)
b'Welcome to xycrypto!'
Example
>>> from xycrypto.ciphers import AES_CBC
# The len(key) is 16 bytes for AES-128, you can use 32 bytes key for AES-256.
>>> key = b'0123456789abcdef'
# Note len(iv) should be equal to AES_CBC.block_size.
>>> iv = b'0123456789abcdef'
# We use PKCS7 padding.
>>> cipher = AES_CBC(key, iv=iv, padding='PKCS7')
>>> plaintext = b'Welcome to xycrypto!'
>>> ciphertext = cipher.encrypt(plaintext)
>>> ciphertext
b'3\x0f\xad\xa6\x17\xc4}\xb9\t\x17\xf8\xae\xbb\xa2t\xb9o\xf2\xf6\x16\t\x0803\xaci\x0c\x19q\x9d\xa3O'
>>> cipher.decrypt(ciphertext)
b'Welcome to xycrypto!'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xycrypto-0.9.tar.gz
(10.6 kB
view details)
Built Distribution
xycrypto-0.9-py3-none-any.whl
(12.3 kB
view details)
File details
Details for the file xycrypto-0.9.tar.gz
.
File metadata
- Download URL: xycrypto-0.9.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aabe16f6d5365cea22bb21421231655309390ee379ab33ecc637e21fa87734d |
|
MD5 | 46f17d1ed1ac69e5261203dd18f7845b |
|
BLAKE2b-256 | 69628317b7175c62d298af7818c34d5d5caf7fd3554cef4d151d4d4b55f03a64 |
File details
Details for the file xycrypto-0.9-py3-none-any.whl
.
File metadata
- Download URL: xycrypto-0.9-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50c5dd993412522c51f646358121aebccd46bedb8f52809078cb32c965d7006 |
|
MD5 | c4834b77521b6da3751e61b3572bb6cc |
|
BLAKE2b-256 | 071d28480638214fa8ddcb29d358a303cceda47568a35ee94ff355878e1ac04e |