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,CFBmode. - nonce for block cipher in
CTRmode. - padding for block cipher in
ECB,CBCmode.
# 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!'
Metadata
Release files for xycrypto 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xycrypto-0.9.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xycrypto-0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.9 kB
Release files / xycrypto-0.9.tar.gz
| Download URL | xycrypto-0.9.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1aabe16f6d5365cea22bb21421231655309390ee379ab33ecc637e21fa87734d
|
|
BLAKE2b-256 checksum How to use checksums |
69628317b7175c62d298af7818c34d5d5caf7fd3554cef4d151d4d4b55f03a64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / xycrypto-0.9-py3-none-any.whl
| Download URL | xycrypto-0.9-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c50c5dd993412522c51f646358121aebccd46bedb8f52809078cb32c965d7006
|
|
BLAKE2b-256 checksum How to use checksums |
071d28480638214fa8ddcb29d358a303cceda47568a35ee94ff355878e1ac04e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|