NSec

NSec is a modern and easy-to-use cryptographic library for .NET 5.0 and .NET Core based on libsodium.

Example

The following C# example shows NSec can be used to sign some data with Ed25519 and verify the signature:

// select the Ed25519 signature algorithm
var algorithm = SignatureAlgorithm.Ed25519;

// create a new key pair
using var key = Key.Create(algorithm);

// generate some data to be signed
var data = Encoding.UTF8.GetBytes("Use the Force, Luke!");

// sign the data using the private key
var signature = algorithm.Sign(key, data);

// verify the data using the signature and the public key
if (algorithm.Verify(key.PublicKey, data, signature))
{
    // verified!
    ...
}

Installation

$ dotnet add package NSec.Cryptography --version 20.11.0-preview1

NSec works with .NET 5.0 as well as .NET Core 3.1 and 2.1 on Windows, Linux and macOS.

See Installation for more information.

Documentation

ClassAlgorithm
AeadAlgorithm ClassAES256-GCM
ChaCha20-Poly1305
HashAlgorithm ClassBLAKE2b (unkeyed)
SHA-256
SHA-512
KeyAgreementAlgorithm ClassX25519
KeyDerivationAlgorithm ClassHKDF-SHA-256
HKDF-SHA-512
MacAlgorithm ClassBLAKE2b (keyed)
HMAC-SHA-256
HMAC-SHA-512
SignatureAlgorithm ClassEd25519

See API Reference for more information.

Contributing

NSec is an open source project. Contributions to the code or documentation are highly welcome.

The development of NSec takes place in its GitHub repository. The easiest way to contribute is by submitting a pull request. Please ask before making a significant pull request (e.g., implementing any new features). If you’ve found a problem with NSec, please open an issue. Feature requests and questions are welcome, too.

Note

“Cryptography is not magic pixie dust that you can sprinkle on a system to make it secure.”

NSec aims to provide careful abstractions to make the work with modern cryptographic primitives relatively easy and pain-free. However, the primitives are not very useful by themselves and need to be combined into higher-level security protocols (such as TLS or CBOR Web Token). Don’t roll your own security protocols.

License

NSec is licensed under the MIT license.