Skip to main content

Super easy asymmetric encryption for python

Introduction

python-asymcrypt is a wrapper around pycryptodome to make it even more easier for asymmetric encryption.

Installation

With pip

pip install asymcrypt

Usage

Generate keys files

import asymcrypt

asymcrypt.generate_keys('my_private_key_file.pem','my_public_key_file.pem')

Encrypt data

data = 'A string, not an unicode'
encrypted_data = asymcrypt.encrypt_data(data,'my_public_key_file.pem')

Decrypt data

data = asymcrypt.decrypt_data(encrypted_data,'my_private_key_file.pem')

Unicode, Str, Bytes

asymcrypt is using pycryptodome which is awaiting, for data, bytes for python3 or str for python2. So it is preferable to use these types. Nevertheless, asymcrypt provides a type detection, it will keep the type you used at encryption time for the decryption time :

For python 2, if you use unicode data for encryption, it will be automatically encoded as utf-8 str before encryption and decoded back to unicode after decryption. If you use str data, no encoding/decoding will be done.

For python 3, if you use str data for encryption, it will be automatically encoded as utf-8 bytes before encryption and decoded back to str after decryption. If you use bytes data, no encoding/decoding will be done.

Passphrase

As an option, you can use passphrase option in each functions to generate encrypted keys and read them when using encrypt/decrypt_data() functions

Base64

By default, output/input are binary. Nevertheless, you can encode into base64 in encrypt_data() by using option out_format='base64' or decode from base64 in decrypt_data() by using option in_format='base64'

Command line

Asymcrypt provides 3 commands :

To generate keys pair

asymgenkeys -priv private_key.pem -pub public_key.pem

To encrypt

asymencrypt -k public_key.pem -in file_to_encrypt.txt -out dest_file.enc

To decrypt

asymdecrypt -k private_key.pem -in encrypted_file.enc -out dest_file.txt

Note : you may use option -b or --base64 to encode/decode in base64 and -p or --passphrase to specify a passphrase to encrypt/decrypt keys

Note 2 : If you do not specify -in or -out in above commands, the standard input/output will be used.

Compatibility with openssl

asymcrypt uses RSA keys, RSA encryption protocol according to PKCS#1 OAEP, AES with EAX AEAD mode. The keys will be encrypted with scrypt And AES128-CBC if a passphrase is provided. The encrypted data keep track of the original python data type. All these make impossible to use openssl directly to decode files generated by asymcrypt.

News

0.0.10 (2019-05-24)

  • Use Python 3.6 in Pipfile

0.0.9 (2019-02-06)

  • fix asymdecrypt script

0.0.6 (2018-10-02)

  • Keep track of orginal data type (unicode, str, bytes)

0.0.4 (2018-10-01)

  • Add console commands

  • Keys files are now cached

0.0.2 (2018-09-28)

  • First running version

Release files for asymcrypt 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asymcrypt 0.0.10
File Size Uploaded
asymcrypt-0.0.10.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asymcrypt 0.0.10
File Interpreter ABI Platform
asymcrypt-0.0.10-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 13.6 kB

Release files / asymcrypt-0.0.10.tar.gz

Download URL asymcrypt-0.0.10.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
979330491f2f79257d128d8e71ea9b7237124a5955316a19a8f176190c71396a
BLAKE2b-256 checksum
How to use checksums
a075ee64d99d0815d1d6a78fc903d3feefce99e8e27f059ca11579c0dc635eb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release files / asymcrypt-0.0.10-py2.py3-none-any.whl

Download URL asymcrypt-0.0.10-py2.py3-none-any.whl
Size 8.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
99f82953937862c4084ec055582ffb102be3719f6e4d8d4bb0a8fe91d8eab5ae
BLAKE2b-256 checksum
How to use checksums
da0ba44d64bc9bc6d85311c0368c2a12041911c4e71e00d30438af9b8a3ad3b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page