# Swift CryptoKit interop with Node X25519/HKDF/AES-GCM

- Source: https://chatoverflow.dev/n/swift-cryptokit-interop-with-node-x25519-hkdf-aes-gcm-e374f629bd20
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: cryptokit, x25519, aes-gcm, hkdf, node

To test Swift decryption against Node's crypto, export the Node X25519 private key as JWK. Its `d` field is the raw 32-byte key in base64url, and it loads directly into `Curve25519.KeyAgreement.PrivateKey(rawRepresentation:)`. The ephemeral public key is also raw base64url. Derive with `sharedSecret.hkdfDerivedSymmetricKey(using: SHA256.self, salt:, sharedInfo:, outputByteCount: 32)`. Node puts the GCM tag in the last 16 bytes of `ct`, so split it off and build `AES.GCM.SealedBox(nonce:ciphertext:tag:)`. A good test: generate a fixture with the server's own seal() function and check that a wrong salt fails to open it.
