Beispiel #1
0
        internal static void ReadPkcs8Blob(this DerSequenceReader reader, ref DSAParameters parameters)
        {
            // Since the PKCS#8 blob for DSS/DSA does not include the public key (Y) this
            // structure is only read after filling the public half.
            Debug.Assert(parameters.P != null);
            Debug.Assert(parameters.Q != null);
            Debug.Assert(parameters.G != null);
            Debug.Assert(parameters.Y != null);

            // OneAsymmetricKey ::= SEQUENCE {
            //   version                   Version,
            //   privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier,
            //   privateKey                PrivateKey,
            //   attributes            [0] Attributes OPTIONAL,
            //   ...,
            //   [[2: publicKey        [1] PublicKey OPTIONAL ]],
            //   ...
            // }
            //
            // PrivateKeyInfo ::= OneAsymmetricKey
            //
            // PrivateKey ::= OCTET STRING

            int version = reader.ReadInteger();

            // We understand both version 0 and 1 formats,
            // which are now known as v1 and v2, respectively.
            if (version > 1)
            {
                throw new CryptographicException();
            }

            {
                // Ensure we're reading DSA, extract the parameters
                DerSequenceReader algorithm = reader.ReadSequence();

                string algorithmOid = algorithm.ReadOidAsString();

                if (algorithmOid != s_idDsa.Value)
                {
                    throw new CryptographicException();
                }

                // The Dss-Params SEQUENCE is present here, but not needed since
                // we got it from the public key already.
            }

            byte[]            privateKeyBlob   = reader.ReadOctetString();
            DerSequenceReader privateKeyReader = DerSequenceReader.CreateForPayload(privateKeyBlob);

            parameters.X = privateKeyReader.ReadIntegerBytes();
        }
Beispiel #2
0
        internal static void ReadSubjectPublicKeyInfo(
            this DerSequenceReader algParameters,
            byte[] publicKeyBlob,
            ref DSAParameters parameters)
        {
            parameters.P = algParameters.ReadIntegerBytes();
            parameters.Q = algParameters.ReadIntegerBytes();
            parameters.G = algParameters.ReadIntegerBytes();

            DerSequenceReader privateKeyReader = DerSequenceReader.CreateForPayload(publicKeyBlob);
            parameters.Y = privateKeyReader.ReadIntegerBytes();

            KeyBlobHelpers.TrimPaddingByte(ref parameters.P);
            KeyBlobHelpers.TrimPaddingByte(ref parameters.Q);

            KeyBlobHelpers.PadOrTrim(ref parameters.G, parameters.P.Length);
            KeyBlobHelpers.PadOrTrim(ref parameters.Y, parameters.P.Length);
        }