skills/cryptography-as-a-service-pattern/SKILL.md
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.
npx skillsauth add igbuend/grimbard cryptography-as-a-service-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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:
Trade-offs:
| Type | Examples | |------|----------| | Cloud-based KMS | Google Cloud KMS, Amazon KMS, Azure Key Vault | | Mobile Platform | Android Keystore, iOS KeyChain | | Hardware | Hardware Security Modules (HSM) |
| Role | Type | Responsibility | |------|------|----------------| | System | Entity | Wants to perform cryptographic operations | | Cryptography Service | Entity | Handles cryptographic operations, key storage, and key management |
Note: The Cryptography Service inherits the Cryptographer role from the parent Cryptographic Key Management pattern.
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.
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.
| Aspect | Cryptography as a Service | Self-Managed Cryptography | |--------|---------------------------|---------------------------| | Key possession | System holds only key identifiers | System holds actual key material | | Key storage | Managed by service | Managed by application | | Key exposure risk | Lower (keys never exposed) | Higher (keys in application memory) | | Trust requirement | Trust the service provider | Trust your own implementation |
The Cryptography Service should be considered an uncontrolled entity, requiring additional measures to secure interactions.
When using cloud-based cryptographic services:
When using platform-provided services:
As the Cryptography Service is an uncontrolled entity, at least part of the communication channel will also be uncontrolled.
Required protections:
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:
While keyId is not the key material itself:
| Consideration | Cloud KMS | Platform Keystore | HSM | |---------------|-----------|-------------------|-----| | Network dependency | Required | No | Varies | | Audit logging | Built-in | Limited | Built-in | | Regulatory compliance | Varies by provider | Platform-dependent | Often required | | Key ceremony | Managed | N/A | Often required | | Multi-cloud support | Provider-specific | Platform-specific | Usually portable |
Always consult the documentation of candidate Cryptography Service(s) to assess:
development
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
development
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.