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)))); }