Skip to main content

Encryption and decryption primitives for gift card data (physical and virtual)

Project description

giftcrypt

Encryption and decryption of 16-digit gift card numbers (physical and virtual).

Version: 1.0.0


Overview

giftcrypt is a Python package used by the GC Activation Orchestrator to encrypt a plain 16-digit gift card number before writing it to Vault DB, and to decrypt it when reading back.

Two backends are supported:

Backend Mechanism When to use
gcm AES-256-GCM local key Local development and testing
kms_wrapped AWS KMS envelope encryption Production (recommended)

Installation

pip install cryptography          # for gcm backend
pip install cryptography boto3    # for kms_wrapped backend

Usage

The only function the Orchestrator needs to call is in vault.py:

from giftcrypt.vault import encrypt_card_number, decrypt_card_number

Local / dev testing (GCM backend)

No AWS needed. Uses a local secret key.

from giftcrypt.vault import encrypt_card_number, decrypt_card_number

key = "my-secret-encryption-key"

# Encrypt — after SVS activates the card (PGC or VGC)
ciphertext = encrypt_card_number(
    "1234567890123456",
    backend="gcm",
    key=key,
)
# → store ciphertext in Vault DB

# Decrypt — when reading back from Vault DB
card_number = decrypt_card_number(ciphertext, backend="gcm", key=key)
assert card_number == "1234567890123456"

Production (KMS wrapped backend)

Requires AWS account and KMS key. Card number never leaves your Lambda.

from giftcrypt.vault import encrypt_card_number, decrypt_card_number

KEY_ALIAS = "alias/giftcard-key"
REGION    = "us-east-1"

# PGC — card number from KIBO shipment swipe
# VGC — card number freshly issued by SVS
# Both use the exact same call:

ciphertext = encrypt_card_number(
    "1234567890123456",
    backend="kms_wrapped",
    key_alias=KEY_ALIAS,
    region=REGION,
)
# → store ciphertext in Vault DB

card_number = decrypt_card_number(ciphertext, backend="kms_wrapped", region=REGION)
assert card_number == "1234567890123456"

Input formats accepted

Dashes and spaces are stripped automatically before encryption:

encrypt_card_number("1234567890123456")      # plain
encrypt_card_number("1234-5678-9012-3456")   # dashes stripped
encrypt_card_number("1234 5678 9012 3456")   # spaces stripped
# all three store the same normalised value: "1234567890123456"

Package structure

giftcrypt/
├── giftcrypt/
│   ├── __init__.py       # package entry point
│   ├── vault.py          # primary interface — validate, normalise, route
│   ├── gcm.py            # AES-256-GCM local encryption
│   └── kms_wrapped.py    # AWS KMS envelope encryption
└── tests/
    ├── test_gcm.py        # 10 tests
    └── test_vault.py      # 21 tests

Running tests

No AWS account needed — KMS is fully mocked:

py -m pytest tests/ -v

Expected output:

31 passed in 0.82s

AWS KMS setup (for production)

  1. Create an AWS account at https://aws.amazon.com/free
  2. Create a KMS key in AWS Console → KMS → Create key
  3. Set alias to alias/giftcard-key
  4. Run aws configure on your machine to set up credentials
  5. Create conf/test.yml:
aws:
  profile: your_aws_profile
  region: us-east-1
  key_alias: alias/giftcard-key
  1. Run the KMS smoke test:
py kms_smoke_test.py

Ciphertext envelope formats

GCM envelope — pipe-separated, base64url-encoded:

v1|<iv>|<tag>|<aad>|<ciphertext>

KMS wrapped envelope — base64-encoded JSON:

{
  "version": "kms-wrapped-v1",
  "key_id": "arn:aws:kms:us-east-1:...",
  "wrapped_data_key": "...",
  "iv": "...",
  "ciphertext": "..."
}

License

MIT

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

giftcrypt-1.0.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

giftcrypt-1.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file giftcrypt-1.0.1.tar.gz.

File metadata

  • Download URL: giftcrypt-1.0.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for giftcrypt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 da78f94ce65391437c238f0647de95079d25a6920e1d04dbd8f77abada059dbc
MD5 09b231ba1d2e5a589a18e3c1b7b9315d
BLAKE2b-256 aaf0c0b88c5498b4b17dbb30bb18fb1c30064bfda0204ad00bd0dcdd05425601

See more details on using hashes here.

File details

Details for the file giftcrypt-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: giftcrypt-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for giftcrypt-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f3ed5994faa940d3f817959ea8bbaeec90d63a458c4ac00e3d774e1ceb2c6b0
MD5 1bf69972b1aa80db225829832d867b8a
BLAKE2b-256 027e6a10da1135f0833e564aef6ebeac0618ae7d58e27ed5bb13e89466206910

See more details on using hashes here.

Supported by

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