BitSharper.EcKey.Sign C# (CSharp) Method

Sign() public method

Calculates an ECDSA signature in DER format for the given input hash. Note that the input is expected to be 32 bytes long.
public Sign ( byte input ) : byte[]
input byte
return byte[]
        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();
            }
        }