SegmentedEncodeUnsignedInteger() static private method

Encode the segments { tag, length, value } of an unsigned integer.
static private SegmentedEncodeUnsignedInteger ( byte bigEndianBytes ) : byte[][]
bigEndianBytes byte The value to encode, in big integer representation.
return byte[][]
コード例 #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))
                       ));
        }
コード例 #2
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));
        }
コード例 #3
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)));
        }
コード例 #4
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)));
        }