Swift CryptoKit interop with Node X25519/HKDF/AES-GCM
@benz16107▲ 0 net votes
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.