| Crates.io | apple-cryptokit-rs |
| lib.rs | apple-cryptokit-rs |
| version | 0.1.0 |
| created_at | 2025-09-03 06:48:48.224674+00 |
| updated_at | 2025-09-03 06:48:48.224674+00 |
| description | A Rust wrapper around Apple's native CryptoKit framework for App Store compliant cryptography. |
| homepage | https://github.com/zibo-chen/apple-cryptokit-rs |
| repository | https://github.com/zibo-chen/apple-cryptokit-rs |
| max_upload_size | |
| id | 1822097 |
| size | 331,191 |
A Rust wrapper around Apple's native CryptoKit framework, designed to provide cryptographic functionality while maintaining App Store compliance.
When submitting apps to the App Store, Apple requires specific handling of cryptographic functionality. Apps that use encryption must either:
This library solves this problem by:
By using this library, your Rust applications can leverage Apple's optimized cryptographic implementations while avoiding the need for additional export compliance paperwork.
Add this to your Cargo.toml:
[dependencies]
apple-cryptokit-rs = "0.1.0"
use apple_cryptokit::hashing::{sha256_hash, SHA256, HashFunction};
fn main() -> apple_cryptokit::Result<()> {
let data = b"Hello, World!";
// Direct function call
let hash1 = sha256_hash(data);
// Using trait
let hash2 = SHA256::hash(data);
println!("SHA-256: {}", hex::encode(hash1));
Ok(())
}
use apple_cryptokit::authentication::{hmac_sha256, HMACSHA256};
fn main() -> apple_cryptokit::Result<()> {
let key = b"my-secret-key";
let message = b"important message";
let mac = hmac_sha256(key, message)?;
println!("HMAC-SHA256: {}", hex::encode(mac));
Ok(())
}
use apple_cryptokit::symmetric::aes::{aes_gcm_encrypt, aes_gcm_decrypt};
fn main() -> apple_cryptokit::Result<()> {
let key = b"0123456789abcdef0123456789abcdef"; // 32-byte key
let nonce = b"cdef01234567"; // 12-byte nonce
let plaintext = b"Secret message";
// Encrypt
let ciphertext = aes_gcm_encrypt(key, nonce, plaintext)?;
// Decrypt
let decrypted = aes_gcm_decrypt(key, nonce, &ciphertext)?;
assert_eq!(plaintext, &decrypted[..]);
Ok(())
}
use apple_cryptokit::asymmetric::p256::{P256PrivateKey, P256PublicKey};
fn main() -> apple_cryptokit::Result<()> {
// Generate key pair
let private_key = P256PrivateKey::new()?;
let public_key = private_key.public_key()?;
// Create shared secret (ECDH)
let other_private = P256PrivateKey::new()?;
let other_public = other_private.public_key()?;
let shared_secret = private_key.shared_secret_from_key_agreement(&other_public)?;
println!("Shared secret established");
Ok(())
}
use apple_cryptokit::quantum::{MLKem768, KEMPrivateKey, KEMPublicKey};
fn main() -> apple_cryptokit::Result<()> {
// Generate ML-KEM-768 key pair
let private_key = MLKem768::generate_private_key()?;
let public_key = private_key.public_key()?;
// Encapsulation (sender side)
let (ciphertext, shared_secret1) = public_key.encapsulate()?;
// Decapsulation (receiver side)
let shared_secret2 = private_key.decapsulate(&ciphertext)?;
// Both parties now have the same shared secret
assert_eq!(shared_secret1, shared_secret2);
Ok(())
}
use apple_cryptokit::quantum::{MLDsa65, SignaturePrivateKey, SignaturePublicKey};
fn main() -> apple_cryptokit::Result<()> {
// Generate ML-DSA-65 key pair
let private_key = MLDsa65::generate_private_key()?;
let public_key = private_key.public_key()?;
let message = b"Document to sign";
// Sign
let signature = private_key.sign(message)?;
// Verify
let is_valid = public_key.verify(message, &signature)?;
assert!(is_valid);
println!("Signature verified!");
Ok(())
}
This library consists of two main components:
swift/ directory): A Swift package that provides C-compatible interfaces to Apple's CryptoKit frameworksrc/ directory): Safe Rust wrappers around the Swift interfacesThe build process uses a custom build.rs script that:
This library is designed to help maintain compliance with U.S. Export Administration Regulations when distributing apps through the App Store. By using only Apple's provided cryptographic implementations, apps using this library may qualify for certain exemptions.
Important: Always consult with legal counsel regarding export compliance requirements for your specific application and use case.
When using this library in an iOS/macOS app, you may need to add the following to your app's Info.plist:
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
Or if your app does use encryption but qualifies for exemptions:
<key>ITSAppUsesNonExemptEncryption</key>
<true/>
<key>ITSEncryptionExportComplianceCode</key>
<string>your-compliance-code-here</string>
cargo build
cargo test
cargo run --example basic_usage
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project was inspired by oml-cryptokit-rs, which pioneered the approach of wrapping Apple's CryptoKit to maintain App Store export compliance. We are grateful for their innovative solution and have built upon their work.
Special thanks to the oml-cryptokit-rs project for:
build.rs implementationThis project is licensed under the MIT License - see the LICENSE file for details.
This library wraps Apple's CryptoKit framework and is intended to help with App Store compliance. However, export compliance requirements can be complex and may vary based on your specific use case, target markets, and implementation details.
Always consult with qualified legal counsel regarding export compliance requirements for your specific application.