Crypto shredding for Python
Project description
Crypto shredding is the practice of ‘deleting’ data through the destruction of the cryptographic keys protecting the data.
You can find the source on GitHub.
Getting Started
Required Prerequisites
Python 3.6+
Installation
Usage
KeyStore
>>> import boto3
>>> from cryptoshredding import DynamodbKeyStore
>>> from dynamodb_encryption_sdk.material_providers.aws_kms import AwsKmsCryptographicMaterialsProvider
>>>
>>> aws_cmk_id = "arn:aws:kms:YOUR_KEY"
>>> aws_kms_cmp = AwsKmsCryptographicMaterialsProvider(key_id=aws_cmk_id)
>>>
>>> table = boto3.resource("dynamodb").Table("key_store_table")
>>>
>>> key_store = DynamodbKeyStore(table=table, materials_provider=aws_kms_cmp)
>>>
>>> key_store.create_main_key("foo")
>>>
>>> main_key = key_store.get_main_key("foo")
>>>
>>> key_store.delete_main_key("foo") # shredding
MainKey
>>> import boto3
>>> from cryptoshredding import MainKey
>>>
>>> main_key = key_store.get_main_key("foo")
>>>
>>> data_key, encrypted_data_key = main_key.generate_data_key()
>>>
>>> decrypted_data_key = main_key.decrypt(encrypted_data_key)
>>>
>>> assert data_key == decrypted_data_key
Dynamodb
>>> import boto3
>>> from cryptoshredding.dynamodb import CryptoTable
>>>
>>> table = boto3.resource("dynamodb").Table("data_table")
>>>
>>> crypto_table = CryptoTable(
... table=table,
... key_store=key_store,
... )
>>> crypto_table.put_item(
... CSEKeyId=key_id,
... Item=plaintext_item
... )
>>>
>>> index_key = {"id": "foo"}
>>> encrypted_item = table.get_item(Key=index_key)["Item"]
>>> decrypted_item = crypto_table.get_item(Key=index_key)["Item"]
>>>
>>> encrypted_items = table.scan()["Items"]
>>> decrypted_items = crypto_table.scan()["Items"]
>>>
>>> assert len(encrypted_items) == 1
>>> assert len(decrypted_items) == 1
>>>
>>> key_store.delete_main_key(key_id) # shredding
>>>
>>> encrypted_items = table.scan()["Items"]
>>> decrypted_items = crypto_table.scan()["Items"]
>>>
>>> assert len(encrypted_items) == 1
>>> assert len(decrypted_items) == 0 # !!!
S3
>>> import boto3
>>> from cryptoshredding.s3 import CryptoClient
>>>
>>> s3 = boto3.client("s3", region_name="us-east-1")
>>>
>>> crypto_client = CryptoClient(
... client=s3,
... key_store=key_store,
... )
>>> crypto_s3.put_object(
... CSEKeyId=key_id,
... Bucket=bucket.name,
... Key="object",
... Body="foo bar"",
... )
>>> encrypted_obj = s3.get_object(
... Bucket=bucket.name,
... Key="object",
... )
>>> decrypted_obj = crypto_s3.get_object(
... Bucket=bucket.name,
... Key="object",
... )
File
>>> from cryptoshredding.raw import CryptoFile
>>>
>>> crypto_file = CryptoFile(
... key_store=key_store,
... )
>>> crypto_file.encrypt(
... key_id=key_id,
... plaintext_filename="plain.txt",
... ciphertext_filename="cipher.txt"
... )
>>> crypto_file.decrypt(
... ciphertext_filename="cipher.txt",
... plaintext_filename="decrypt.txt",
... )
Bytes
>>> from cryptoshredding.raw import CryptoBytes
>>>
>>> crypto_bytes = CryptoBytes(
... key_store=key_store,
... )
>>> encrypted, encrypted_header = crypto_bytes.encrypt(
... key_id=key_id,
... data=plain,
... )
>>> decrypted, decrypted_header = crypto_bytes.decrypt(
... data=encrypted,
... )
Kinesis
Mongodb
Sqlalchemy
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
cryptoshredding-0.0.4.tar.gz
(12.3 kB
view details)
Built Distribution
File details
Details for the file cryptoshredding-0.0.4.tar.gz
.
File metadata
- Download URL: cryptoshredding-0.0.4.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7672ea692c8f282244303f0666803aa2453e49800ea8635ad2d7880af40a85fb |
|
MD5 | d43c6dc5695d10602246bff44ee81282 |
|
BLAKE2b-256 | 785249748df2dda4a43e249324c3508473fb76f6e4b8190dccd629b0ed149688 |
File details
Details for the file cryptoshredding-0.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: cryptoshredding-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b275621187f6a7064816568fcd7ca9c91f741bb19159bffce798468bace03d5 |
|
MD5 | 7a79e0d7cc5d2ef1a76a86a636fe8b3d |
|
BLAKE2b-256 | cd82b2e3604df3d10d7f2d0e51d618e1e387cc261e0ff0fc5fe2e7ac0cd47069 |