Skip to main content
net10.0-ios26.2net10.0-maccatalyst26.2net10.0-macos26.2net10.0-tvos26.2

Native Swift interop bindings for Apple CryptoKit

Published
Aug 24, 2026
1mo ago
Total Downloads
1.6K
1,575

Install

dotnet add package SwiftBindings.Apple.CryptoKit --version 26.2.11
ProductVersions
.NET
net10.0-ios26.2net10.0-maccatalyst26.2net10.0-macos26.2net10.0-tvos26.2

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 bare net10.0-ios whose installed workload defaults below 26.2 fails restore with NU1202. 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

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 arbitrary DataProtocol type)
  • 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

No structural changes between v26.2.10 and v26.2.11.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.