C# Platform Guide
Overview
MetaMUI.Crypto provides a comprehensive cryptographic library for .NET applications, supporting .NET 6.0+ and .NET Framework 4.7.2+. Available through enterprise licensing, it offers individual algorithm packages and convenient suite packages.
Installation
Enterprise Setup
# Download and run the installer
# Contact sales@metamui.id for access
MetaMUI.Crypto.Installer.exe --license-key YOUR_LICENSE_KEY
# Configure local NuGet source
dotnet nuget add source C:\MetaMUI\Crypto\packages --name "MetaMUI Enterprise"
NuGet Configuration
Create or update NuGet.config in your solution root:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MetaMUI Enterprise" value="C:\MetaMUI\Crypto\packages" />
</packageSources>
<packageSourceCredentials>
<MetaMUI>
<add key="Username" value="license" />
<add key="ClearTextPassword" value="YOUR_LICENSE_KEY" />
</MetaMUI>
</packageSourceCredentials>
</configuration>
Package Installation
Individual Algorithms
<!-- In your .csproj file -->
<PackageReference Include="MetaMUI.Crypto.Blake3" Version="3.0.0-enterprise" />
<PackageReference Include="MetaMUI.Crypto.MlKem768" Version="3.0.0-enterprise" />
<PackageReference Include="MetaMUI.Crypto.ChaCha20Poly1305" Version="3.0.0-enterprise" />
Suite Packages
<!-- PQC Suite: All NIST post-quantum algorithms -->
<PackageReference Include="MetaMUI.Crypto.PQCSuite" Version="3.0.0-enterprise" />
<!-- KPQC Suite: Korean post-quantum algorithms -->
<PackageReference Include="MetaMUI.Crypto.KPQCSuite" Version="3.0.0-enterprise" />
<!-- Recommended Suite: Curated algorithm selection -->
<PackageReference Include="MetaMUI.Crypto.RecommendedSuite" Version="3.0.0-enterprise" />
Command Line Installation
# Install individual packages
dotnet add package MetaMUI.Crypto.Blake3 --version 3.0.0-enterprise
dotnet add package MetaMUI.Crypto.MlKem768 --version 3.0.0-enterprise
# Install suite packages
dotnet add package MetaMUI.Crypto.PQCSuite --version 3.0.0-enterprise
Usage Examples
Basic Hashing with BLAKE3
using MetaMUI.Crypto.Blake3;
// Simple hashing
byte[] data = Encoding.UTF8.GetBytes("Hello, World!");
byte[] hash = Blake3.ComputeHash(data);
Console.WriteLine($"BLAKE3 Hash: {Convert.ToHexString(hash)}");
// Streaming hash
using var hasher = new Blake3Hasher();
hasher.Update(data1);
hasher.Update(data2);
byte[] finalHash = hasher.Finalize();
// Keyed hashing (MAC)
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
byte[] mac = Blake3.ComputeKeyedHash(key, data);
Post-Quantum Key Exchange (ML-KEM-768)
using MetaMUI.Crypto.PostQuantum;
using MetaMUI.Crypto.MlKem768;
public class QuantumSafeKeyExchange
{
public static void DemonstrateKEM()
{
// Generate keypair
var (publicKey, secretKey) = MlKem768.GenerateKeypair();
// Sender: Encapsulate shared secret
var (ciphertext, sharedSecretSender) = MlKem768.Encapsulate(publicKey);
// Receiver: Decapsulate shared secret
byte[] sharedSecretReceiver = MlKem768.Decapsulate(ciphertext, secretKey);
// Verify shared secrets match
bool match = sharedSecretSender.SequenceEqual(sharedSecretReceiver);
Console.WriteLine($"Shared secrets match: {match}");
// Use shared secret for symmetric encryption
using var aes = Aes.Create();
aes.Key = sharedSecretSender;
}
}
Authenticated Encryption (ChaCha20-Poly1305)
using MetaMUI.Crypto.ChaCha20Poly1305;
public class SecureMessaging
{
public static (byte[] ciphertext, byte[] tag) Encrypt(
byte[] plaintext,
byte[] key,
byte[] nonce,
byte[] associatedData = null)
{
using var cipher = new ChaCha20Poly1305(key);
byte[] ciphertext = new byte[plaintext.Length];
byte[] tag = new byte[16];
cipher.Encrypt(nonce, plaintext, ciphertext, tag, associatedData);
return (ciphertext, tag);
}
public static byte[] Decrypt(
byte[] ciphertext,
byte[] tag,
byte[] key,
byte[] nonce,
byte[] associatedData = null)
{
using var cipher = new ChaCha20Poly1305(key);
byte[] plaintext = new byte[ciphertext.Length];
cipher.Decrypt(nonce, ciphertext, tag, plaintext, associatedData);
return plaintext;
}
}
Digital Signatures with Dilithium
using MetaMUI.Crypto.PQCSuite;
public class QuantumSafeSignatures
{
public static void DemonstrateSignatures()
{
// Generate signing keypair
var (publicKey, privateKey) = Dilithium3.GenerateKeypair();
// Sign a message
byte[] message = Encoding.UTF8.GetBytes("Important document");
byte[] signature = Dilithium3.Sign(message, privateKey);
// Verify signature
bool valid = Dilithium3.Verify(message, signature, publicKey);
Console.WriteLine($"Signature valid: {valid}");
// Secure key disposal
privateKey.SecureDispose();
}
}
Password Hashing with Argon2id
using MetaMUI.Crypto.Argon2;
public class PasswordManager
{
public static string HashPassword(string password)
{
// Generate salt
byte[] salt = new byte[16];
RandomNumberGenerator.Fill(salt);
// Hash with Argon2id
var hasher = new Argon2id
{
Salt = salt,
MemorySize = 65536, // 64 MB
Iterations = 4,
DegreeOfParallelism = 2
};
byte[] hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(password));
// Return encoded string (includes parameters)
return hasher.GetEncodedString();
}
public static bool VerifyPassword(string password, string encodedHash)
{
return Argon2id.Verify(encodedHash, password);
}
}
Suite Package Usage
PQC Suite Example
using MetaMUI.Crypto.PQCSuite;
public class PostQuantumCrypto
{
public static void UsePQCSuite()
{
// ML-KEM for key exchange
var (kemPk, kemSk) = PQC.MlKem768.GenerateKeypair();
var (ct, shared) = PQC.MlKem768.Encapsulate(kemPk);
// ML-DSA for signatures
var (dsaPk, dsaSk) = PQC.MlDsa65.GenerateKeypair();
byte[] signature = PQC.MlDsa65.Sign(message, dsaSk);
// Falcon for compact signatures
var (falconPk, falconSk) = PQC.Falcon512.GenerateKeypair();
byte[] compactSig = PQC.Falcon512.Sign(message, falconSk);
// SLH-DSA for stateless signatures
var (slhPk, slhSk) = PQC.SlhDsaShake256f.GenerateKeypair();
byte[] statelessSig = PQC.SlhDsaShake256f.Sign(message, slhSk);
}
}
KPQC Suite Example
using MetaMUI.Crypto.KPQCSuite;
public class KoreanPQC
{
public static void UseKPQCSuite()
{
// SMAUG-T for key encapsulation
var (smaugPk, smaugSk) = KPQC.SmaugT3.GenerateKeypair();
// Haetae for signatures
var (haetaePk, haetaeSk) = KPQC.Haetae3.GenerateKeypair();
// AIMer for MPC-based signatures
var (aimerPk, aimerSk) = KPQC.Aimer128f.GenerateKeypair();
// NTRU+ for alternative KEM
var (ntruPk, ntruSk) = KPQC.NtruPlus768.GenerateKeypair();
}
}
Async Operations
using MetaMUI.Crypto.Async;
// Async hashing for large files
public async Task<byte[]> HashLargeFileAsync(string filePath)
{
using var stream = File.OpenRead(filePath);
return await Blake3.ComputeHashAsync(stream);
}
// Async encryption
public async Task<byte[]> EncryptAsync(byte[] data, byte[] key)
{
return await Task.Run(() =>
{
using var cipher = new ChaCha20Poly1305(key);
// Perform encryption
return encryptedData;
});
}
Secure Memory Management
using MetaMUI.Crypto.Security;
// Secure string handling
using (var secureString = new SecureString())
{
foreach (char c in password)
secureString.AppendChar(c);
// Use secure string
byte[] key = SecureStringUtils.DeriveKey(secureString);
// Automatic secure disposal
}
// Secure byte arrays
using (var secureBytes = new SecureByteArray(32))
{
RandomNumberGenerator.Fill(secureBytes.Buffer);
// Use secure bytes
// Automatically zeroed on disposal
}
Dependency Injection
// Startup.cs or Program.cs
builder.Services.AddMetaMUICrypto(options =>
{
options.LicenseKey = Configuration["MetaMUI:LicenseKey"];
options.EnableHardwareAcceleration = true;
options.SecureMemoryPoolSize = 1024 * 1024; // 1 MB
});
// In your service
public class CryptoService
{
private readonly IHashProvider _hashProvider;
private readonly IKemProvider _kemProvider;
public CryptoService(IHashProvider hashProvider, IKemProvider kemProvider)
{
_hashProvider = hashProvider;
_kemProvider = kemProvider;
}
public byte[] HashData(byte[] data)
{
return _hashProvider.ComputeHash(HashAlgorithm.Blake3, data);
}
}
Performance Benchmarks
| Algorithm | Operation | Time (ms) | Throughput |
|---|---|---|---|
| BLAKE3 | Hash 1 MB | 0.8 | 1.25 GB/s |
| ChaCha20-Poly1305 | Encrypt 1 MB | 1.2 | 833 MB/s |
| ML-KEM-768 | Key Generation | 0.05 | 20,000 ops/s |
| Dilithium3 | Sign | 0.3 | 3,333 ops/s |
Platform Support
| Framework | Version | Support |
|---|---|---|
| .NET 8.0 | Latest | ✅ Full |
| .NET 7.0 | Latest | ✅ Full |
| .NET 6.0 | LTS | ✅ Full |
| .NET Framework 4.8 | Latest | ✅ Full |
| .NET Framework 4.7.2 | Min | ⚠️ Limited |
| .NET Standard 2.1 | - | ✅ Full |
| .NET Standard 2.0 | - | ⚠️ Limited |
Error Handling
try
{
var result = MlKem768.Encapsulate(publicKey);
}
catch (CryptographicException ex)
{
// Handle crypto-specific errors
Logger.LogError($"Cryptographic error: {ex.Message}");
}
catch (InvalidKeyException ex)
{
// Handle key-related errors
Logger.LogError($"Invalid key: {ex.Message}");
}
catch (MetaMUILicenseException ex)
{
// Handle licensing issues
Logger.LogError($"License error: {ex.Message}");
}
License Management
using MetaMUI.Crypto.Licensing;
// Check license status
var licenseInfo = LicenseManager.GetLicenseInfo();
Console.WriteLine($"License valid until: {licenseInfo.ExpiryDate}");
Console.WriteLine($"Algorithms licensed: {licenseInfo.AlgorithmCount}");
// Validate specific algorithm access
if (LicenseManager.IsAlgorithmLicensed("ML-KEM-768"))
{
// Use ML-KEM-768
}
// Handle license events
LicenseManager.LicenseExpiring += (sender, args) =>
{
Logger.LogWarning($"License expiring in {args.DaysRemaining} days");
};
Support Resources
- API Documentation: Included in package
- Sample Projects:
C:\MetaMUI\Crypto\samples\ - Support Portal: support.metamui.id
- Enterprise Support: enterprise-support@metamui.id
- Stack Overflow: Tag
metamui-crypto