LibAscon128 1.0.1

dotnet add package LibAscon128 --version 1.0.1
                    
NuGet\Install-Package LibAscon128 -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LibAscon128" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LibAscon128" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="LibAscon128" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LibAscon128 --version 1.0.1
                    
#r "nuget: LibAscon128, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LibAscon128@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LibAscon128&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=LibAscon128&version=1.0.1
                    
Install as a Cake Tool

About

Library for Ascon-AEAD128 encryption/decryption, and Ascon-Hash256 / Ascon-XOF128 hashing

How to use

Currently the basic API is similar to C based one. There is also a fancy API for easier operations.

❗ If you are using Ascon-AEAD128, do NOT reuse same key + nonce combination. Always change at least the nonce when you create a new encrypted message ❗

C style API example

Ascon-AEAD128
using CSAscon;

// Message that will be encrypted 
byte[] message = System.Text.Encoding.UTF8.GetBytes("This message should be encrypted");

// Associated data
byte[] associatedData = System.Text.Encoding.UTF8.GetBytes("Associated data");

// Nonce (MUST be 16 bytes)
byte[] nonce = new byte[] { 206, 74, 86, 166, 217, 45, 90, 73, 240, 65, 165, 45, 215, 47, 94, 73 };

// Key (MUST be 16 bytes)
byte[] key = new byte[] { 101, 101, 174, 222, 224, 97, 156, 94, 123, 183, 109, 219, 208, 135, 104, 122 };

// Preallocate storage for encrypted data
byte[] encryptedMessage = new byte[message.Length + 16];

// Encrypt
int func_ret = Asconaead128.crypto_aead_encrypt(encryptedMessage, out int clen, message, message.Length, associatedData, associatedData.Length, null, nonce, key);

// Decrypt
byte[] decryptedMessage = new byte[message.Length];
func_ret = Asconaead128.crypto_aead_decrypt(decryptedMessage, out mlen2, null, encryptedMessage, clen, associatedData, associatedData.Length, nonce, key);
Ascon-Hash256
using CSAscon;

byte[] input = new byte[21] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
byte[] outputHash = new byte[32];

// Hash
int returnValue = Asconhash256.crypto_hash(outputHash, input);

(the hash is always 32 bytes / 256 bits)

Ascon-XOF128
using CSAscon;

byte[] input = new byte[21] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
int outputLength = 64;
byte[] outputHash = new byte[outputLength];
int returnValue = Asconxof128.crypto_hash(outputHash, input);

Fancy API bytes example

Ascon-AEAD128
using CSAscon;

ReadOnlySpan<byte> message = "This is a very long and boring text for testing purposes 😀 !"u8;
ReadOnlySpan<byte> associatedData = "My associated data"u8;

ReadOnlySpan<byte> nonce = "MY_CAT_IS_NOT_IT"u8;
ReadOnlySpan<byte> key = "DO_NOT_USE_IN_PR"u8; // Use better key in real life

// Encrypt
byte[] encryptedMessage = Asconaead128.Encrypt(message, associatedData, nonce, key);

// Decrypt
byte[] decryptedMessage = Asconaead128.Decrypt(encryptedMessage, associatedData, nonce, key);
Ascon-Hash256
using CSAscon;

byte[] input = new byte[21] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };

// Hash
byte[] hash = Asconhash256.HashBytes(input);

(the hash is always 32 bytes / 256 bits)

Ascon-XOF128
using CSAscon;

byte[] input = new byte[21] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
int outputLength = 64;

// Hash
byte[] hash = Asconxof128.HashBytes(input, outputLength);

Fancy API stream example

Ascon-AEAD128
using CSAscon;

FileStream inputStream = File.OpenRead("fileToEncrypt.txt");
MemoryStream encryptedStream = new MemoryStream();

ReadOnlySpan<byte> associatedData = "My associated data"u8;
ReadOnlySpan<byte> nonce = "MY_CAT_IS_NOT_IT"u8;
ReadOnlySpan<byte> key = "DO_NOT_USE_IN_PR"u8; // Use better key in real life

// Encrypt
Asconaead128.Encrypt(inputStream, encryptedStream, associatedData, nonce, key);

// Decrypt
FileStream encryptedFileStream = File.OpenRead("mySecretFile.sec");
MemoryStream decryptedStream = new MemoryStream();
int shouldBeZero = Asconaead128.Decrypt(encryptedFileStream, decryptedStream, associatedData, nonce, key);
Ascon-Hash256
using CSAscon;

FileStream inputStream = File.OpenRead("holiday.jpg");

// Hash
byte[] hash = Asconhash256.HashBytes(inputStream);

(the hash is always 32 bytes / 256 bits)

Ascon-XOF128
using CSAscon;

FileStream inputStream = File.OpenRead("holiday.jpg");
int outputLength = 64;

// Hash
byte[] hash = Asconxof128.HashBytes(inputStream, outputLength);

Fancy API stream async example

Ascon-AEAD128
using CSAscon;

FileStream inputStream = File.OpenRead("fileToEncrypt.txt");
MemoryStream encryptedStream = new MemoryStream();

ReadOnlySpan<byte> associatedData = "My associated data"u8;
ReadOnlySpan<byte> nonce = "MY_CAT_IS_NOT_IT"u8;
ReadOnlySpan<byte> key = "DO_NOT_USE_IN_PR"u8; // Use better key in real life

// Encrypt
await Asconaead128.EncryptAsync(inputStream, encryptedStream, associatedData, nonce, key);

// Decrypt
FileStream encryptedFileStream = File.OpenRead("mySecretFile.sec");
MemoryStream decryptedStream = new MemoryStream();
int shouldBeZero = await Asconaead128.DecryptAsync(encryptedFileStream, decryptedStream, associatedData, nonce, key);
Ascon-Hash256
using CSAscon;

FileStream inputStream = File.OpenRead("holiday.jpg");

// Hash
byte[] hash = await Asconhash256.HashBytesAsync(inputStream);

(the hash is always 32 bytes / 256 bits)

Ascon-XOF128
using CSAscon;

FileStream inputStream = File.OpenRead("holiday.jpg");
int outputLength = 64;

// Hash
byte[] hash = await Asconxof128.HashBytesAsync(inputStream, outputLength);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 140 6/24/2026
1.0.0 118 6/4/2026
0.9.1 381 11/15/2025
0.9.0 752 4/13/2023

## Version 1.0.1 (released 2026-06-24)
- Add stream processing versions of methods (**FEATURE**)

## Version 1.0.0 (released 2026-06-04)
- Added Ascon-AEAD128, Ascon-Hash256 and Ascon-XOF128 (**FEATURE**)
- Library is now `IsAotCompatible` (**FEATURE**)
- Dropped Ascon128av12 and Ascon128v12 (**BREAKING**)

## Version 0.9.1 (released 2025-11-15)
- .NET 8 and .NET 10 update

## Version 0.9.0 (released 2023-04-13)
- First nuget release