BitSharper.EcKey.GetPrivKeyBytes C# (CSharp) Method

GetPrivKeyBytes() public method

Returns a 32 byte array containing the private key.
public GetPrivKeyBytes ( ) : byte[]
return byte[]
        public byte[] GetPrivKeyBytes()
        {
            // Getting the bytes out of a BigInteger gives us an extra zero byte on the end (for signedness)
            // or less than 32 bytes (leading zeros).  Coerce to 32 bytes in all cases.
            var bytes = new byte[32];

            var privArray = _priv.ToByteArray();
            var privStart = (privArray.Length == 33) ? 1 : 0;
            var privLength = Math.Min(privArray.Length, 32);
            Array.Copy(privArray, privStart, bytes, 32 - privLength, privLength);

            return bytes;
        }