Card security

Tokenization vs encryption: only one of them shrinks your PCI scope

Encrypting card numbers feels like the responsible thing to do, and it is, right up to the moment you find out your encrypted database is still fully in PCI scope. Tokenization is what takes systems out. Here's the difference, what the PCI Council says about each, where point-to-point encryption fits, and the vault and encryption material from chapter 17.

This is engineering guidance, not legal advice. Scope decisions are your assessor's and your acquirer's to confirm, not this page's.

Encryption turns a card number into ciphertext that anyone holding the key can turn back into the card number. Tokenization replaces the card number with a surrogate value, a token, and keeps the real number in a separate vault; the PCI Council's guidance is that recovering the card number from the token alone must not be computationally feasible (PCI SSC).

The difference that matters for compliance is scope. Encrypted card data is still card data. A system that holds only tokens, and can't get the card number back, can fall out of scope.

EncryptionTokenization
What you holdThe card number, scrambledA stand-in with no card number in it
Reversible byAnyone with the keyOnly the tokenization system, by looking up the vault
PCI scopeStill in scope where the key is reachable. "Encryption alone is insufficient to render the cardholder data out of scope" (PCI SSC FAQ 1086)Systems that hold only tokens, are segmented from the vault and can't de-tokenize may be out of scope (PCI SSC)
Where it's required anywayIn transit everywhere, and at rest for any card number you store. Strong encryption is an accepted way to make stored card numbers unreadable under requirement 3.5.1 (PCI SSC FAQ 1086)Nowhere. It's a design choice
FormatCiphertext, usually longer than the inputAnything, often shaped like a card number so old systems accept it

Why encryption doesn't take you out of scope

The key is the problem. If the system holding encrypted card numbers, or anyone with access to it, can reach the decryption key, the data is as good as plaintext to an attacker who gets that far. The PCI Council's narrow exception is for a third party that receives only data encrypted by someone else: it "may be able to consider the encrypted data out of scope" if it has no access to the decryption keys or to the clear-text data (PCI SSC FAQ 1233). If you encrypted it, you have the keys, so it doesn't apply to you.

Why tokenization can, and when it can't

The PCI Council's tokenization guidelines are specific about what has to be true. The tokenization system itself, including the vault and de-tokenization, is always in scope. A system that stores or handles only tokens can be out of scope if, among other conditions, the card number can't be recovered from the tokens, the system is segmented from anything that can de-tokenize or reach the vault or keys, it isn't connected to the cardholder data environment, and any card data it held before has been securely deleted (PCI SSC).

Two things in that guidance catch teams out:

  • If you can get the card number back, you're in scope. The guidelines say that if the merchant can retrieve the card number, the merchant's environment is in scope (PCI SSC). Running your own vault is tokenization, but it doesn't shrink your scope much: the vault is yours, so it's in your scope.
  • Some "tokens" are encrypted card numbers. A token generated by reversible encryption of the card number "is an encrypted PAN", and may carry PCI DSS considerations beyond the tokenization guidance (PCI SSC). Ask how a vendor's tokens are generated before you count on them.

Where the card number is typed matters more than either

Tokenization only takes your systems out of scope if the card number never passes through them on the way to the vault. If your server receives the card number and then calls an API to tokenize it, your server handled card data, and it's in scope. That's the difference between SAQ D and SAQ A, and it's why the scope win comes from letting your processor collect the card on its own page or iframe and hand you back a token like a Stripe PaymentMethod ID. Your database then holds IDs your processor can charge and you can't reverse. PCI scope has the SAQ that each integration lands you in.

Point-to-point encryption: the exception for terminals

For card-present payments, encryption does shrink scope, but only a validated kind run by someone else. A PCI-listed point-to-point encryption (P2PE) solution encrypts the card at the terminal and decrypts it only inside the provider's environment. The PCI Council says it "can significantly reduce the number of PCI DSS requirements applicable" but "does not completely remove the applicability of PCI DSS" (PCI SSC FAQ 1158). It works for the same reason as the FAQ 1233 exception: you never hold the keys.

Tokens from the network, not the processor

Processor tokens only work with that processor. Card networks issue their own tokens too, which replace the card number with a network credential and stay current when the card is reissued. Those are about approval rates more than scope; network tokens covers them.

What a vault does with the card number once it has it: envelope encryption, and why there are two keys. From chapter 17.

Vault Architecture: Where Tokens Live

A secure vault is a specialized database for sensitive data. The SecureVault class in src/examples/17-compliance/pci_tokenization_system.py uses envelope encryption: each piece of data gets encrypted with its own data key, and that data key is then encrypted with a master key.

# Envelope encryption pattern (conceptual)
def encrypt(data):
    # 1. Generate unique data key
    data_key = generate_random_key(256)

    # 2. Encrypt data with data key (symmetric)
    encrypted_data = aes_encrypt(data, data_key)

    # 3. Encrypt data key with master key (asymmetric)
    encrypted_key = rsa_encrypt(data_key, master_key)

    # 4. Securely wipe data key from memory
    secure_wipe(data_key)

    return {encrypted_data, encrypted_key}

This approach provides defense-in-depth: even if the encrypted data is compromised, the attacker still needs the master key to decrypt the data keys.

If you do have to hold sensitive data, how to encrypt it so tampering shows and keys can rotate. From chapter 17.

Encryption Best Practices

If you absolutely must handle sensitive data, use authenticated encryption with key rotation. The reference implementation in src/examples/17-compliance/compliance_encryption.py provides PaymentEncryption (AES-256-GCM with automatic 90-day rotation), EncryptionKey lifecycle metadata, and a KeyStore for versioned key storage.

# Authenticated encryption pattern (conceptual)
def encrypt_card(card_data):
    # 1. Get current encryption key (supports rotation)
    key = key_store.get_current_key()

    # 2. Generate unique IV (NEVER reuse with same key!)
    iv = generate_random_bytes(12)  # 96 bits for GCM

    # 3. Encrypt with authenticated mode (prevents tampering)
    ciphertext, auth_tag = aes_256_gcm_encrypt(
        plaintext=card_data,
        key=key.material,
        iv=iv,
        associated_data=metadata  # Authenticated but not encrypted
    )

    return {
        'encrypted': ciphertext,
        'iv': iv,
        'auth_tag': auth_tag,  # Verifies integrity
        'key_id': key.id,      # For key rotation support
        'algorithm': 'aes-256-gcm'
    }

The full code adds automatic 90-day key rotation, secure key versioning, re-encryption workflows, and HSM integration patterns.

Hosted tokenization, P2PE and segmentation, in one paragraph. From chapter 26.

Reducing PCI Scope

Hosted tokenization (your processor's payment page or iframe) can move you from SAQ D, which covers nearly the whole standard, to SAQ A, which covers a short list of controls. Validated point-to-point encryption (P2PE) terminals get their own short form, SAQ P2PE. Pair that with network segmentation that isolates the cardholder data environment (CDE) from the general network, and everything outside the segment drops out of scope.

Questions

What is the difference between tokenization and encryption?

Encryption scrambles the card number so anyone with the key can reverse it. Tokenization replaces the card number with a surrogate token and keeps the real number in a separate vault, so the card number can't feasibly be recovered from the token alone.

Does encryption reduce PCI scope?

Not on its own. The PCI Council says encryption alone is insufficient to take cardholder data out of scope. The exception is a third party that only receives data someone else encrypted and has no access to the keys or the clear-text data.

Does tokenization reduce PCI scope?

It can. Systems that hold only tokens, can't de-tokenize, and are segmented from the vault and the cardholder data environment may be out of scope. The tokenization system itself is always in scope, and if you can retrieve the card number, your environment is too.

What is payment tokenization?

Replacing a card number with a token that's useless outside the system that issued it. In practice your processor collects the card on its own page or iframe and gives you a token to charge later, so your systems never handle the card number.

Is P2PE encryption or tokenization?

Encryption. A PCI-listed point-to-point encryption solution encrypts the card at the terminal and decrypts it only in the provider's environment. The PCI Council says it can significantly reduce the PCI DSS requirements that apply, but doesn't remove PCI DSS entirely.

What the book adds

The rest of chapter 17

  • A full tokenization system, from vault to audit log
  • Network tokens vs gateway tokens
  • What counts as card data, and what's safe to store
  • The SAQ types, and which one your checkout lands you in
  • Key rotation and HSM integration

30-day money-back · Instant PDF and EPUB

All 42 chapters