0

I've been going in circles trying to get a simple ed25519 signature verification working. Had success with libsodium third party library but then ran into issues with it and am back to the drawing board. I see system.security.cryptography.ecdsa but it's not clear to me if it's possible to get that to work with a ed25519 signature. I'm kind of surprised there aren't code examples of doing this sig verification in .Net because I thought ed25519 was a reasonably common algorithm?

Is there a Microsoft library for ed25519 signature verification? Or can anyone provide an example of how to successfully do this in .Net?

Joe Tonka
  • 11
  • 1
  • 1
    Nothing in the MS libs for this. However, if you are using .NET then you can try: https://github.com/nitrachain/NitraLibSodium – Brian Webb Jan 23 '20 at 18:59
  • 1
    ty, but i tried libsodium and it can't run on azure due to dll issues seemingly (https://stackoverflow.com/questions/37347620/libsodium-net-unable-to-load-dll-libsodium-dll/37526795 the vs 2015 redistributable isn't available). every alternative i've found seems to be a wrapper for libsodium which i'd imagine would have the same problem unfortunately – Joe Tonka Jan 23 '20 at 19:48

1 Answers1

2

You can use BouncyCastle for this purpose. Below is the code example of how I am doing it. For using this code make sure the publicKey and signature are hex strings.

public Task<bool> VerifySignature(string publicKey, string dataToVerify, string signature)
{
    var publicKeyParam = new Ed25519PublicKeyParameters(Hex.DecodeStrict(publicKey));
    var dataToVerifyBytes = Encoding.UTF8.GetBytes(dataToVerify);
    var signatureBytes = Convert.FromHexString(signature);

    var verifier = new Ed25519Signer();
    verifier.Init(false, publicKeyParam);
    verifier.BlockUpdate(dataToVerifyBytes, 0, dataToVerifyBytes.Length);
    var isVerified = verifier.VerifySignature(signatureBytes);
    return Task.FromResult(isVerified);
}
Brian Barnes
  • 135
  • 1
  • 6