cryptography-as-a-service-pattern

Security pattern for delegating cryptographic operations and key management to an external service. Use when designing systems that should not possess cryptographic keys directly. Implementation of Cryptographic Key Management pattern. Examples include Android Keystore, iOS KeyChain, AWS KMS, Azure Key Vault, Google Cloud KMS. Reduces risk of key leakage and cipher misconfiguration.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "cryptography-as-a-service-pattern" with this command: npx skills add igbuend/grimbard/igbuend-grimbard-cryptography-as-a-service-pattern

Cryptography as a Service Security Pattern

In this pattern, the management of cryptographic keys is delegated to the same entity that performs the cryptographic actions. Consequently, the system under design never possesses the used cryptographic keys.

Benefits and Trade-offs

Benefits:

  • Limits risk of leaking cryptographic keys
  • Reduces risk of incorrectly configuring and/or using a cipher
  • System only handles key identifiers, not key material

Trade-offs:

  • Requires greater trust in the entity providing cryptographic operations
  • Dependency on external service availability

Common Implementations

TypeExamples
Cloud-based KMSGoogle Cloud KMS, Amazon KMS, Azure Key Vault
Mobile PlatformAndroid Keystore, iOS KeyChain
HardwareHardware Security Modules (HSM)

Core Components

RoleTypeResponsibility
SystemEntityWants to perform cryptographic operations
Cryptography ServiceEntityHandles cryptographic operations, key storage, and key management

Note: The Cryptography Service inherits the Cryptographer role from the parent Cryptographic Key Management pattern.

Data Elements

  • keyConf: Configuration for key generation (e.g., symmetric/asymmetric, key length) - optional
  • keyId: Identifier returned by the service to reference the generated key
  • input: Plaintext input for cryptographic action
  • output: Result of cryptographic action (e.g., ciphertext, signature)
  • config: Configuration for the cryptographic operation (e.g., cipher mode) - optional
  • masterKey: Credential used to authenticate the System to the Cryptography Service

Actions

  • generate_key: Generate new cryptographic key according to configuration
  • crypto_action: Perform cryptographic operation using the identified key

Pattern Flow

Key Generation

System → [generate_key(keyConf)] → Cryptography Service
Cryptography Service → [keyId] → System

The System requests key generation with optional configuration. The Cryptography Service generates the key internally and returns only an identifier (not the key material) for future operations.

Cryptographic Action

System → [crypto_action(input, keyId, config)] → Cryptography Service
Cryptography Service → [output] → System

To use a previously generated key, the System provides the keyId received during generation. The key material never leaves the Cryptography Service.

Key Difference from Self-Managed Cryptography

AspectCryptography as a ServiceSelf-Managed Cryptography
Key possessionSystem holds only key identifiersSystem holds actual key material
Key storageManaged by serviceManaged by application
Key exposure riskLower (keys never exposed)Higher (keys in application memory)
Trust requirementTrust the service providerTrust your own implementation

Security Considerations

The Cryptography Service as Uncontrolled Entity

The Cryptography Service should be considered an uncontrolled entity, requiring additional measures to secure interactions.

Cloud-based Services (Google Cloud KMS, Amazon KMS)

When using cloud-based cryptographic services:

  • All interactions travel via the public Internet
  • Confidentiality and integrity of exchanged messages must be ensured
  • Authentication is critical—verify you're interacting with the actual service, not an attacker spoofing it
  • Use TLS/HTTPS for all communications
  • Implement proper service authentication (API keys, certificates, IAM)

Mobile Platform Services (Android Keystore, iOS KeyChain)

When using platform-provided services:

  • Service is a local entity provided by the underlying platform
  • Communication channel is typically more controlled
  • Still verify platform-specific security guarantees
  • Consider device compromise scenarios

Communication Channel Security

As the Cryptography Service is an uncontrolled entity, at least part of the communication channel will also be uncontrolled.

Required protections:

  • Confidentiality of requests (especially for encryption/decryption operations)
  • Integrity of requests and responses
  • Authentication of the service endpoint

Master Key Handling

The master key is used as a credential to authenticate the System to the Cryptography Service.

Critical: The master key should be treated as a credential:

  • Store securely (environment variables, secrets manager)
  • Never hardcode in source code
  • Rotate periodically
  • Limit access to minimal required principals

Key Identifier (keyId) Protection

While keyId is not the key material itself:

  • Protect against unauthorized tampering during storage
  • An attacker who can modify keyId might redirect operations to a different key
  • Consider encrypting or signing stored key identifiers

Implementation Checklist

  • Selected appropriate Cryptography Service for your use case
  • Reviewed service documentation for security guarantees
  • Secured communication channel (TLS, certificate validation)
  • Master key stored and managed as a credential
  • Key identifiers protected from tampering
  • Service authentication properly configured
  • Considered service availability and failure modes
  • Implemented proper error handling for service failures
  • Documented which keys are used for which purposes

Service Selection Considerations

ConsiderationCloud KMSPlatform KeystoreHSM
Network dependencyRequiredNoVaries
Audit loggingBuilt-inLimitedBuilt-in
Regulatory complianceVaries by providerPlatform-dependentOften required
Key ceremonyManagedN/AOften required
Multi-cloud supportProvider-specificPlatform-specificUsually portable

Consult Service Documentation

Always consult the documentation of candidate Cryptography Service(s) to assess:

  • Security guarantees for interactions between your system and the service
  • Key protection mechanisms (hardware backing, encryption at rest)
  • Audit and compliance capabilities
  • Service Level Agreements (SLAs)
  • Key backup and disaster recovery procedures

Related Patterns

  • Cryptographic Key Management (parent pattern)
  • Self-Managed Cryptography (alternative implementation)
  • Cryptographic Action (uses keys managed by this pattern)
  • Encryption (specific cryptographic action)
  • Digital Signature (specific cryptographic action)

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Security

oauth-security-anti-pattern

No summary provided by upstream source.

Repository SourceNeeds Review
Security

content-security-policy

No summary provided by upstream source.

Repository SourceNeeds Review
General

tikz

No summary provided by upstream source.

Repository SourceNeeds Review