Home

Awesome

Virgil Crypto Library Python

Travis (.com) PyPI PyPI PyPI

Introduction | Library purposes | Installation | Usage examples | Docs | License | Contacts

Introduction

Virgil Crypto Library Python is a wrapper over Virgil Crypto Library C. It provides a bunch of custom hybrid algorithms that combine different crypto algorithms to solve common complex cryptographic problems in an easy way. That eliminates the requirement for developers to have strong cryptographic skills in order to add a security layer to their applications.

Library purposes

Installation

Installing prerequisites

Install latest pip distribution: download get-pip.py and run it using the python interpreter.

Installing from wheel binary packages

We provide binary packages for all the supported platforms. Use pip to install the wheel binary packages:

pip install virgil-crypto

Usage examples

Generate a key pair

Generate a private key using the default algorithm (EC_X25519):

from virgil_crypto import VirgilCrypto

crypto = VirgilCrypto()
key_pair = crypto.generate_key_pair()

Generate and verify a signature

Generate signature and sign data with a private key:

from virgil_crypto import VirgilCrypto

crypto = VirgilCrypto()
key_pair = crypto.generate_key_pair()
sender_private_key = key_pair.private_key

message_to_sign = "Hello, Bob!"
data_to_sign = message_to_sign.encode()

signature = crypto.generate_signature(data_to_sign, sender_private_key)

Verify a signature with a public key:

from virgil_crypto import VirgilCrypto

crypto = VirgilCrypto()

verified = crypto.verify_signature(data_to_sign, signature, sender_public_key)

Encrypt and decrypt data

Encrypt data with a public key:

from virgil_crypto import VirgilCrypto

crypto = VirgilCrypto()

message_to_encrypt = "Hello, Bob!"
data_to_encrypt = message_to_encrypt.encode()

reciver_list = [reciver_public_key]
encrypted_data = crypto.encrypt(data_to_encrypt, *reciver_list)

Decrypt the encrypted data with a private key:

from virgil_crypto import VirgilCrypto

crypto = VirgilCrypto()

decrypted_data = crypto.decrypt(encrypted_data, reciver_private_key)
decrypted_message = bytes(decrypted_data).decode()

Import and export keys

Export keys:

crypto = VirgilCrypto()

# generate a Key Pair
key_pair = crypto.generate_keys()

# export a Private key
private_key_data = crypto.export_private_key(key_pair.private_key, "[YOUR_PASSWORD]")
base64.b64encode(private_key_data)

# export a Public key
public_key_data = crypto.export_public_key(key_pair.public_key, "[YOUR_PASSWORD]")
base64.b64encode(public_key_data)

Import keys:

crypto = VirgilCrypto()
private_key_str = "MIGhMF0GCSqGSIb3DQEFDTBQMC8GCSqGSIb3DQEFDDAiBBBtfBoM7VfmWPlvyHuGWvMSAgIZ6zAKBggqhkiG9w0CCjAdBglghkgBZQMEASoEECwaKJKWFNn3OMVoUXEcmqcEQMZ+WWkmPqzwzJXGFrgS/+bEbr2DvreVgEUiLKrggmXL9ZKugPKG0VhNY0omnCNXDzkXi5dCFp25RLqbbSYsCyw="
private_key_data = base64.b64decode(private_key_str)

# import a Private key
crypto.import_private_key(private_key_data, "[YOUR_PASSWORD]")

//-----------------------------------------------------

crypto = VirgilCrypto()
public_key_str = "MCowBQYDK2VwAyEA9IVUzsQENtRVzhzraTiEZZy7YLq5LDQOXGQG/q0t0kE="
public_key_data = base64.b64decode(public_key_str)

# import a Public key
crypto.import_public_key(public_key_data)

Docs

License

This library is released under the 3-clause BSD License.

Support

Our developer support team is here to help you. Find out more information on our Help Center.

You can find us on Twitter or send us email support@VirgilSecurity.com.

Also, get extra help from our support team on Slack.