Native Swift interop bindings for Apple CryptoKit
Install
| Product | Versions |
|---|---|
| .NET |
README
SwiftBindings.Apple.CryptoKit
Native .NET bindings for Apple's CryptoKit framework — hashing, symmetric and authenticated encryption, key agreement, and signatures. These are not Objective-C proxy wrappers; they use .NET 10's native Swift interop for direct, high-performance calls into Swift APIs from C#.
📖 Full usage guide → — Swift→C# naming, authenticated encryption (AES-GCM/ChaChaPoly), hashing, HMAC, key agreement, ECDSA signatures, and the generic-overload caveats that decide which APIs are callable.
Installation
dotnet add package SwiftBindings.Apple.CryptoKit
Requirements
- .NET 10.0+
- Target framework:
net10.0-ios26.2(or-macos26.2/-maccatalyst26.2/-tvos26.2) or higher. The package is compiled against the iOS 26.2 SDK supplement, so your app's<TargetFramework>platform version must be ≥ 26.2 to restore it — an explicit lower TPV (e.g.net10.0-ios18.0) or a barenet10.0-ioswhose installed workload defaults below 26.2 fails restore withNU1202. This is the compile-SDK pin, not your app's deployment minimum. - Deployment minimum is separate — set your app's real minimum OS with
<SupportedOSPlatformVersion>(independent of the TFM above). Individual APIs that need a newer OS at runtime are gated by generated[SupportedOSPlatform]attributes; the C# compiler flags a call that isn't valid for your target. - macOS host for development
Usage
Hashing
using System.Text;
using CryptoKit;
var data = Encoding.UTF8.GetBytes("hello");
var digest = SHA256.Hash(data);
Authenticated encryption (AES-GCM)
using System.Text;
using CryptoKit;
var key = new SymmetricKey(SymmetricKeySize.Bits256);
var plaintext = Encoding.UTF8.GetBytes("secret message");
var sealedBox = AES.GCM.Seal(plaintext, key);
var recovered = AES.GCM.Open(sealedBox, key);
ChaChaPoly
var key = new SymmetricKey(SymmetricKeySize.Bits256);
var sealedBox = ChaChaPoly.Seal(plaintext, key);
var recovered = ChaChaPoly.Open(sealedBox, key);
Authenticated encryption with associated data
var aad = Encoding.UTF8.GetBytes("authenticated-header");
var sealedBox = AES.GCM.Seal(plaintext, key, aad);
// sealedBox.Ciphertext / sealedBox.Tag are exposed as byte[]
Documentation
- Usage guide (wiki) — full C# walkthrough of the binding surface
- Apple CryptoKit framework
Caveats
The primary AEAD round-trip (AES.GCM and ChaChaPoly Seal/Open) is verified end-to-end on both Mono JIT (simulator) and NativeAOT (device).
A residual cluster of ancillary CryptoKit APIs are emitted as [Obsolete("SB0001")] stubs and are not callable from C# in this release:
- HMAC constructor
- Signature generation (P-256/P-384/P-521 ECDSA
signature(for:)) - HPKE
Unwrap/Decapsulate/ExportSecret AES.GCM.Open<TAD>(the generic overload that takes authenticated-data of an arbitraryDataProtocoltype)- The 3-argument
IsValidSignature(_:for:)overload
Tamper detection is exercised via wrong-key Open (which throws authenticationFailure) rather than the SealedBox(nonce:ciphertext:tag:) constructor (a Swift generic init the binding generator does not yet emit).
How It Works
These bindings are auto-generated by Swift Dotnet Bindings using .NET 10's native Swift interop via the SwiftBindings SDK.
License
The bindings are MIT licensed. CryptoKit is part of the Apple SDK; refer to Apple's licensing for the underlying framework.
Changes from Previous Version
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.