System.Security.Cryptography.DerEncoder.SegmentedEncodeOctetString C# (CSharp) Method

SegmentedEncodeOctetString() static private method

Encode the segments { tag, length, value } of an octet string (byte array).
static private SegmentedEncodeOctetString ( byte data ) : byte[][]
data byte The data to encode
return byte[][]
        internal static byte[][] SegmentedEncodeOctetString(byte[] data)
        {
            Debug.Assert(data != null);

            // Because this is not currently public API the data array is not being cloned.
            return new byte[][]
            {
                new byte[] { (byte)DerSequenceReader.DerTag.OctetString }, 
                EncodeLength(data.Length),
                data,
            };
        }

Usage Example

        internal static byte[] ToPrivateKeyBlob(this ECParameters parameters)
        {
            parameters.Validate();

            if (!parameters.Curve.IsNamed)
            {
                throw new PlatformNotSupportedException(SR.Cryptography_ECC_NamedCurvesOnly);
            }

            byte[] pointBlob = GetPointBlob(ref parameters);

            // ECPrivateKey{CURVES:IOSet} ::= SEQUENCE {
            //   version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
            //   privateKey OCTET STRING,
            //   parameters [0] Parameters{{IOSet}} OPTIONAL,
            //   publicKey  [1] BIT STRING OPTIONAL
            // }
            return(DerEncoder.ConstructSequence(
                       s_encodedVersion1,
                       DerEncoder.SegmentedEncodeOctetString(parameters.D),
                       DerEncoder.ConstructSegmentedContextSpecificValue(
                           0,
                           DerEncoder.SegmentedEncodeOid(parameters.Curve.Oid)),
                       DerEncoder.ConstructSegmentedContextSpecificValue(
                           1,
                           DerEncoder.SegmentedEncodeBitString(pointBlob))));
        }