Git Product home page Git Product logo

xchacha-dotnet's Introduction

XChaCha-DotNet

Build status

A .NET wrapper for the XChaCha constructions and APIs provided by libsodium crypto library.

The API supports the new Span<T> and ReadOnlySpan<T> types.

Currently only supports .NET Core 2.1.

Algorithms and APIs

XChaCha-DotNet contains the following ciphers:

Class Algorithm Description
XChaChaAeadCipher XChaCha20-Poly1305 IETF AEAD XChaCha AEAD cipher with 192-bit nonce and 192-bit key. Poly-1305 used to compute the authentication tag. Supports Additional Authenticated Data. Can safely encrypt messages up to 2^64 bytes.
XChaChaStream XChaCha20-Poly1305 XChaCha20 stream cipher using Poly-1305 to compute the authentication tags. Automatically generates and rotates nonces. Supports using Additional Authenticated Data. Can safely encrypt messages up to any practical limit.
XChaChaBufferedStream XChaCha20-Poly1305 XChaCha20 stream cipher using Poly-1305 to compute the authentication tags. Automatically generates and rotates nonces and buffers the input stream to encrypt data in fixed sized blocks. Can safely encrypt messages up to any practical limit.
XChaChaSecretBoxCipher XChaCha20-Poly1305 An implementation of the secret_box API in the NaCl crypto library using XChaCha20 for the cipher and Poly-1305 to compute the authentication tag.

Installation

Install from nuget:

Using the dotnet CLI:

dotnet add package xchacha-dotnet

Using the package manager:

Install-Package xchacha-dotnet

Quick Example

Example encryption/decryption using the XChaChaAeadCipher:

Encryption

using (var key = XChaChaKey.Generate())
{
    var aeadCipher = new XChaChaAeadCipher();
    var nonce = XChaChaNonce.Generate();
    var message = Encoding.UTF8.GetBytes("Test Message");
    var ciphertext = aeadCipher.Encrypt(message, key, nonce);
}

Decryption

var keyBytes = Convert.FromBase64String("XPRT6QuYZDdytKM55WW+gnZklhaJBcDnOWi1kEI2we4=");
var nonceBytes = Convert.FromBase64String("2eQuiE8Fy70rwlCAi5T2oVEj5MrwxJaT");
var ciphertext = Convert.FromBase64String("w2jUPkWL0PfvnNFM7xq4o9gcVKrMTkd6SsYhLQ==");
using (var key = new XChaChaKey(keyBytes))
{
    var aeadCipher = new XChaChaAeadCipher();
    var nonce = new XChaChaNonce(nonceBytes);
    var message = aeadCipher.Decrypt(ciphertext, key, nonce);
}

Contributing

Please raise issues to report bugs or request new features. Pull requests welcome.

xchacha-dotnet's People

Contributors

tom-auger avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.