Back to Skills

cryptokit

Use Apple CryptoKit for Swift cryptographic primitives. Use when hashing with SHA-2 or SHA-3, generating HMACs, encrypting with AES-GCM or ChaChaPoly, signing with P256/P384/P521/Curve25519 or ML-DSA keys, performing ECDH, HPKE, ML-KEM, or X-Wing key exchange, using Secure Enclave CryptoKit keys, or migrating CommonCrypto code to CryptoKit.

841stars43forksUpdated 7/7/2026

Security Assessment

Low Risk(70/100)

Detected risks:

Secret Exposure([SKILL.md] Secret =)
Security Score70/100

About cryptokit

A reference for using Apple CryptoKit, the Swift-native cryptography API, to implement primitives correctly and idiomatically. It covers hashing (SHA-256/384/512, plus SHA3-256/384/512 on newer OS versions), HMAC message authentication, authenticated symmetric encryption with AES-GCM and ChaChaPoly, public-key signing with the NIST P256/P384/P521 curves and Curve25519/Ed25519, ECDH key agreement, HPKE, post-quantum APIs (ML-KEM, ML-DSA, X-Wing), and Secure Enclave-backed keys. It advises preferring CryptoKit over CommonCrypto or the raw Security framework for new primitive code, and flags OS availability: most core primitives on iOS 13+, HPKE on iOS 17+, and SHA-3 and post-quantum APIs on iOS 26+ behind availability checks.

Each area comes with concise Swift examples and safe defaults. Hashing shows one-shot, incremental, and digest-comparison patterns, warning against converting digests to strings or arrays for security-sensitive equality. HMAC verification uses constant-time comparison via isValidAuthenticationCode. Symmetric encryption produces a sealed box (nonce, ciphertext, tag), demonstrates AES-GCM and ChaChaPoly, and shows additional authenticated data for tamper-proof metadata, with .bits256 as the default key size. Signing includes a table for choosing a curve (P256 by default, Curve25519 for Ed25519 interop, noting Secure Enclave support), and key agreement stresses that a SharedSecret must be run through a KDF, HKDF by default or X9.63 for interop, with a non-empty sharedInfo to bind the key to a protocol context.

Use it when writing or reviewing Swift code that hashes, authenticates, encrypts, signs, performs key exchange, or uses Secure Enclave keys, and when migrating CommonCrypto code to CryptoKit. It also recommends HPKE for encrypting to a recipient public key instead of hand-rolling ECDH plus HKDF plus AEAD. Beyond the inline snippets, the skill points to a cryptokit-patterns reference for key serialization (DER, PEM, X9.63, and raw representations) and includes common-mistakes and review-checklist sections.

FAQ

Which OS versions are required for the newer primitives?

Most core primitives run on iOS 13+, but HPKE needs iOS 17+ and SHA-3 and the post-quantum APIs need iOS 26+, which should be used behind availability checks.

Which symmetric ciphers does it cover?

AES-GCM (the default, hardware-accelerated on Apple silicon) and ChaChaPoly, both authenticated and producing a sealed box of nonce, ciphertext, and tag, with support for additional authenticated data.

Can I use a SharedSecret directly as an encryption key?

No. A SharedSecret from ECDH must be run through a key derivation function (HKDF by default, or X9.63 for interop), ideally with a non-empty sharedInfo to bind it to a protocol context.

Which signing curve should I default to?

P256 by default (it also supports the Secure Enclave); use Curve25519/Ed25519 for interoperating with Ed25519-based protocols, and P384/P521 for higher security requirements.

Does it help migrate from CommonCrypto?

Yes. It recommends preferring CryptoKit over CommonCrypto and the raw Security framework for new primitive code and is meant to be used when migrating CommonCrypto code to CryptoKit.

All Files

3 files
references/cryptokit-patterns.md17.0 KB
View
SKILL.md14.0 KB
View
evals/evals.json3.0 KB
View

Install cryptokit

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill