ConstructSequence() static private method

Make a constructed SEQUENCE of the byte-triplets of the contents. Each byte[][] should be a byte[][3] of {tag (1 byte), length (1-5 bytes), payload (variable)}.
static private ConstructSequence ( ) : byte[]
return byte[]
Esempio n. 1
0
        internal static byte[] ToSubjectPublicKeyInfo(this DSAParameters parameters)
        {
            // SubjectPublicKeyInfo::= SEQUENCE  {
            //    algorithm AlgorithmIdentifier,
            //    subjectPublicKey     BIT STRING  }

            // Dss-Parms ::= SEQUENCE {
            //   p INTEGER,
            //   q INTEGER,
            //   g INTEGER
            // }

            return(DerEncoder.ConstructSequence(
                       DerEncoder.ConstructSegmentedSequence(
                           DerEncoder.SegmentedEncodeOid(s_idDsa),
                           DerEncoder.ConstructSegmentedSequence(
                               DerEncoder.SegmentedEncodeUnsignedInteger(parameters.P),
                               DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Q),
                               DerEncoder.SegmentedEncodeUnsignedInteger(parameters.G)
                               )
                           ),
                       DerEncoder.SegmentedEncodeBitString(
                           DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Y))
                       ));
        }
Esempio n. 2
0
        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))));
        }
Esempio n. 3
0
        internal static byte[] ToSubjectPublicKeyInfo(this RSAParameters parameters)
        {
            Debug.Assert(parameters.D == null);

            // SubjectPublicKeyInfo::= SEQUENCE  {
            //    algorithm AlgorithmIdentifier,
            //    subjectPublicKey     BIT STRING  }
            return(DerEncoder.ConstructSequence(
                       s_encodedRsaAlgorithmIdentifier,
                       DerEncoder.SegmentedEncodeBitString(
                           parameters.ToPkcs1Blob())));
        }
Esempio n. 4
0
        private static byte[] ConvertToOpenSslFormat(byte[] input)
        {
            Debug.Assert(input != null);
            Debug.Assert(input.Length % 2 == 0);
            Debug.Assert(input.Length > 1);

            // Input is (r, s), each of them exactly half of the array.
            // Output is the DER encoded value of CONSTRUCTEDSEQUENCE(INTEGER(r), INTEGER(s)).
            int halfLength = input.Length / 2;

            byte[][] rEncoded = DerEncoder.SegmentedEncodeUnsignedInteger(input, 0, halfLength);
            byte[][] sEncoded = DerEncoder.SegmentedEncodeUnsignedInteger(input, halfLength, halfLength);

            return(DerEncoder.ConstructSequence(rEncoded, sEncoded));
        }
Esempio n. 5
0
        internal static byte[] ToSubjectPublicKeyInfo(this ECParameters parameters)
        {
            parameters.Validate();

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

            byte[] pointBlob = GetPointBlob(ref parameters);

            return(DerEncoder.ConstructSequence(
                       DerEncoder.ConstructSegmentedSequence(
                           s_encodedIdEcPublicKey,
                           DerEncoder.SegmentedEncodeOid(parameters.Curve.Oid)),
                       DerEncoder.SegmentedEncodeBitString(pointBlob)));
        }
Esempio n. 6
0
        internal static byte[] ToPkcs1Blob(this RSAParameters parameters)
        {
            if (parameters.Exponent == null || parameters.Modulus == null)
            {
                throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
            }

            if (parameters.D == null)
            {
                if (parameters.P != null ||
                    parameters.DP != null ||
                    parameters.Q != null ||
                    parameters.DQ != null ||
                    parameters.InverseQ != null)
                {
                    throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
                }

                return(DerEncoder.ConstructSequence(
                           DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Modulus),
                           DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Exponent)));
            }

            if (parameters.P == null ||
                parameters.DP == null ||
                parameters.Q == null ||
                parameters.DQ == null ||
                parameters.InverseQ == null)
            {
                throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
            }

            return(DerEncoder.ConstructSequence(
                       DerEncoder.SegmentedEncodeUnsignedInteger(s_versionNumberBytes),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Modulus),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Exponent),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.D),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.P),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Q),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.DP),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.DQ),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.InverseQ)));
        }
Esempio n. 7
0
        internal static byte[] ToPrivateKeyBlob(this DSAParameters parameters)
        {
            Debug.Assert(parameters.X != null);

            // DSAPrivateKey ::= SEQUENCE(
            //   version INTEGER,
            //   p INTEGER,
            //   q INTEGER,
            //   g INTEGER,
            //   y INTEGER,
            //   x INTEGER,
            // )

            return(DerEncoder.ConstructSequence(
                       DerEncoder.SegmentedEncodeUnsignedInteger(new byte[] { 0 }),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.P),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Q),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.G),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.Y),
                       DerEncoder.SegmentedEncodeUnsignedInteger(parameters.X)));
        }