Skip to content

Cross platform C# wrapper for the native secp256k1 lib (netstandard2.0)

License

Notifications You must be signed in to change notification settings

cmayorga/Secp256k1.Net

 
 

Repository files navigation

Secp256k1.Net

NuGet

CI Platform Build
AppVeyor Windows & Ubuntu Build status
TravisCI Linux x64 Build Status
TravisCI MacOS x64 Build Status

Cross platform C# wrapper for the native secp256k1 library.

The nuget package supports win-x64, win-x86, macOS-x64, and linux-x64 out of the box. The native libraries are bundled from the Secp256k1.Native package. This wrapper should work on any other platform that supports netstandard2.0 (.NET Core 2.0+, Mono 5.4+, etc) but requires that the native secp256k1 library be compiled from source.


Example Usage

// Create a secp256k1 context (ensure disposal to prevent unmanaged memory leaks).
using (var secp256k1 = new Secp256k1())
{

    // Generate a private key.
    var privateKey = new byte[32];
    var rnd = System.Security.Cryptography.RandomNumberGenerator.Create();
    do { rnd.GetBytes(privateKey); }
    while (!secp256k1.SecretKeyVerify(privateKey));


    // Create public key from private key.
    var publicKey = new byte[64];
    Debug.Assert(secp256k1.PublicKeyCreate(publicKey, privateKey));


    // Sign a message hash.
    var messageBytes = Encoding.UTF8.GetBytes("Hello world.");
    var messageHash = System.Security.Cryptography.SHA256.Create().ComputeHash(messageBytes);
    var signature = new byte[64];
    Debug.Assert(secp256k1.Sign(signature, messageHash, privateKey));


    // Verify message hash.
    Debug.Assert(secp256k1.Verify(signature, messageHash, publicKey));

}

See the tests project for more complex examples of using recoverable and serialization functions.

About

Cross platform C# wrapper for the native secp256k1 lib (netstandard2.0)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%