Skip to main content

pd_cipher::crypto

Core cryptographic types and operations. Core cryptographic operations for token-based encryption.

This module provides the fundamental types and operations for working with tokenized and encrypted data in the PD.Cipher SDK.

Types

  • [Plaintext] - Represents a sequence of unencrypted tokens.
  • PDContext - Context metadata for decrypting tokens.

Workflow

The typical encryption workflow is:

  1. Create a PDCipher.
  2. Generate or load a Key.
  3. Create tokenized data from your input.
  4. Call encryption methods to produce encrypted tokens and context.
  5. Store encrypted tokens and context separately for efficient ML inference.
  6. Call decryption methods with tokens and context to recover the original data.

Type Aliases

Token

Represents a single, unencrypted piece of data ready for encryption.

In the context of text processing, a token is typically a word, but it can be any meaningful unit of data. This is the raw input before encryption.

Usage in SDK

Tokens are the fundamental unit of data that PD.Cipher processes. They are:

  • Input to encryption operations
  • Classified as numeric or string types
  • Processed through the tokenization pipeline
  • Converted to deterministic cipher tokens

Examples

  • Text tokens: b"Alice", b"sends", b"money"
  • Numeric tokens: b"123.45", b"1000"
  • Binary data: Any sequence of bytes representing structured data
pub type Token = ...

CipherToken

Represents a single, encrypted token.

This is the encrypted, deterministic representation that corresponds to a plaintext Token. The same plaintext token always produces the same CipherToken, enabling pattern preservation for machine learning applications.

Security Properties

  • Deterministic: Same input → same output (for ML training)
  • Encrypted: Content is cryptographically protected
  • Truncated: Typically 8-16 characters vs 128-character raw hash
pub type CipherToken = ...