Skip to main content

Horizontal Lockupblack Horizontal Lockup copywhite

Anvil Encryption

PyPI License PyPI Version

This library is a small wrapper around the pypa/cryptography library. It offers convenience methods for encrypting and decrypting arbitrary payloads in both AES and RSA.

For use encrypting / decrypting payloads in Anvil, you can generate an RSA keypair from your organization's settings page.

Anvil provides easy APIs for all things paperwork.

  1. PDF filling API - fill out a PDF template with a web request and structured JSON data.
  2. PDF generation API - send markdown or HTML and Anvil will render it to a PDF.
  3. Etch E-sign with API - customizable, embeddable, e-signature platform with an API to control the signing process end-to-end.
  4. Anvil Workflows (w/ API) - Webforms + PDF + E-sign with a powerful no-code builder. Easily collect structured data, generate PDFs, and request signatures.

Learn more about Anvil on our Anvil developer page.

Setup

Requirements

  • Python 3.7+

Installation

Install it directly into an activated virtual environment:

$ pip install python-anvil-encryption

or add it to your Poetry project:

$ poetry add python-anvil-encryption

Usage

This usage example is also in a runnable form in the examples/ directory.

import os
from python_anvil_encryption import encryption

CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))

# Keys could be read from a file (or preferably from environment variables)
public_key = None
private_key = None
with open(os.path.join(CURRENT_PATH, "keys/public.pub"), "rb") as pub_file:
    public_key = pub_file.read()

with open(os.path.join(CURRENT_PATH, "./keys/private.pem"), "rb") as priv_file:
    private_key = priv_file.read()

# RSA
message = b"Super secret message"
encrypted_message = encryption.encrypt_rsa(public_key, message)
decrypted_message = encryption.decrypt_rsa(private_key, encrypted_message)
assert decrypted_message == message
print(f"Are equal? {decrypted_message == message}")

# AES
aes_key = encryption.generate_aes_key()
aes_encrypted_message = encryption.encrypt_aes(aes_key, message)
# The aes key in the first parameter is required to be in a hex
# byte string format.
decrypted_message = encryption.decrypt_aes(
    aes_key.hex().encode(),
    aes_encrypted_message
)
assert decrypted_message == message
print(f"Are equal? {decrypted_message == message}")

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_anvil_encryption-0.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_anvil_encryption-0.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file python_anvil_encryption-0.1.tar.gz.

File metadata

  • Download URL: python_anvil_encryption-0.1.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.9 Linux/6.4.6-76060406-generic

File hashes

Hashes for python_anvil_encryption-0.1.tar.gz
Algorithm Hash digest
SHA256 565c3feb44d93fb6cf96c0363ded997bad23ee433219270ad67ff576b9a1b9b1
MD5 2f71ffea7aae465c5e5aa9d7314bc6f9
BLAKE2b-256 6238e5759a23d0104f5aa9e3e63d4ce03cf5cb2d77258bd016fef94cbd87c007

See more details on using hashes here.

File details

Details for the file python_anvil_encryption-0.1-py3-none-any.whl.

File metadata

  • Download URL: python_anvil_encryption-0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.9 Linux/6.4.6-76060406-generic

File hashes

Hashes for python_anvil_encryption-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55382d4d00b91ac0fb7716add07880b46d920fbdd5ada3a563fa45b0c06c0c80
MD5 427c61e9a6e31d5d5e693aefd8218ae8
BLAKE2b-256 108ff82755c45072ddd280cfa737e114fd99936b2db5daf356e9918eb78f0743

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page