skills/cryptographic-key-management-pattern/SKILL.md
Security pattern for managing cryptographic keys throughout their lifecycle. Use when integrating cryptography requiring key generation, storage, distribution, or usage. Provides guidance on key confidentiality, integrity, configuration protection, and key information handling. Foundation for Cryptography as a service and Self-managed cryptography patterns.
npx skillsauth add igbuend/grimbard cryptographic-key-management-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.
When integrating cryptographic primitives into a system, correctly managing cryptographic keys is a crucial aspect. This pattern encapsulates common issues when applying solutions involving cryptography.
Proper key management is one of the most crucial aspects when applying cryptography.
Any security guarantees provided by a cryptosystem can be nullified if an attacker can obtain or tamper with the used cryptographic key(s).
Example: An attacker that obtains a supposedly secret session key will be able to decrypt all messages encrypted with that key.
In most circumstances, cryptographic keys should be:
Exception: For some types of keys, such as the public key in an asymmetric key pair, the confidentiality requirement can be relaxed (but integrity must still be protected).
| Role | Type | Responsibility | |------|------|----------------| | Entity | Entity | Wants to generate and use cryptographic keys | | Cryptographer | Cryptographic Primitive | Library generating keys and performing cryptographic actions |
Entity → [generate_key(keyConf)] → Cryptographer
Cryptographer → [keyInfo] → Entity
The Entity requests key generation with optional configuration. The Cryptographer generates the key and returns information needed to use it in future requests.
Entity → [crypto_action(input, keyInfo, config)] → Cryptographer
Cryptographer → [output] → Entity
To use a previously generated key, Entity provides keyInfo received during generation along with input data and optional configuration.
If key configuration is provided, it should be protected from undetected tampering:
Risk Example: An attacker may change key configuration to generate a shorter key than advised, making ciphertexts easier to break.
After generating a key, Entity receives keyInfo which it will process and use in further interactions.
The exact information and necessary security measures depend on the chosen implementation pattern.
If Entity provides action configuration to Cryptographer:
This pattern has two main implementations:
Throughout a key's lifecycle, ensure:
| Phase | Confidentiality | Integrity | |-------|----------------|-----------| | Generation | Protect output | Protect configuration | | Storage | Encrypt at rest | Detect tampering | | Distribution | Secure channel | Verify authenticity | | Usage | Limit exposure | Validate before use | | Rotation | Secure transition | Complete replacement | | Destruction | Secure deletion | Confirm destruction |
| Key Type | Confidentiality | Integrity | |----------|----------------|-----------| | Symmetric key | Required | Required | | Asymmetric private key | Required | Required | | Asymmetric public key | Can be relaxed | Required |
Note: Even public keys require integrity protection—an attacker substituting a public key can compromise the entire system.
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.