コード例 #1
0
        // Parse the contents of a certificate data block.
        private void Parse(byte[] data)
        {
            // Clone the data for internal storage.
            rawData = (byte[])(data.Clone());

            // Parse the ASN.1 data to get the field we are interested in.
            ASN1Parser parser   = new ASN1Parser(rawData);
            ASN1Parser signed   = parser.GetSequence();
            ASN1Parser certInfo = signed.GetSequence();

            if (certInfo.Type == ASN1Parser.ContextSpecific(0))
            {
                // Skip the version field.
                certInfo.Skip();
            }
            serialNumber = certInfo.GetContentsAsArray(ASN1Type.Integer);
            ASN1Parser algId = certInfo.GetSequence();

            issuer = ParseName(certInfo);
            ASN1Parser validity = certInfo.GetSequence();

            effectiveDate  = validity.GetUTCTime();
            expirationDate = validity.GetUTCTime();
            name           = ParseName(certInfo);
            ASN1Parser keyInfo = certInfo.GetSequence();

            algId        = keyInfo.GetSequence();
            keyAlgorithm = ToHex(algId.GetObjectIdentifier());
            if (algId.IsAtEnd() || algId.IsNull())
            {
                keyAlgorithmParameters = null;
            }
            else
            {
                keyAlgorithmParameters = algId.GetWholeAsArray();
            }
            publicKey = keyInfo.GetBitString();

#if CONFIG_CRYPTO
            // Construct an MD5 hash of the certificate.  Is this correct?
            MD5 md5 = new MD5CryptoServiceProvider();
            md5.InternalHashCore(rawData, 0, rawData.Length);
            hash = md5.InternalHashFinal();
            md5.Initialize();
#endif
        }