public byte[] Sign(byte[] input)
{
var signer = new ECDsaSigner();
var privKey = new ECPrivateKeyParameters(_priv, _ecParams);
signer.Init(true, privKey);
var sigs = signer.GenerateSignature(input);
// What we get back from the signer are the two components of a signature, r and s. To get a flat byte stream
// of the type used by BitCoin we have to encode them using DER encoding, which is just a way to pack the two
// components into a structure.
using (var bos = new MemoryStream())
{
var seq = new DerSequenceGenerator(bos);
seq.AddObject(new DerInteger(sigs[0]));
seq.AddObject(new DerInteger(sigs[1]));
seq.Close();
return bos.ToArray();
}
}