GetBytes() public method

public GetBytes ( ) : byte[]
return byte[]
        protected override ASN1 ToBeSigned(string oid)
        {
            // TBSCertificate
            ASN1 tbsCert = new ASN1(0x30);

            if (version > 1)
            {
                // TBSCertificate / [0] Version DEFAULT v1,
                byte[] ver = { (byte)(version - 1) };
                ASN1   v   = tbsCert.Add(new ASN1(0xA0));
                v.Add(new ASN1(0x02, ver));
            }

            // TBSCertificate / CertificateSerialNumber,
            tbsCert.Add(new ASN1(0x02, sn));

            // TBSCertificate / AlgorithmIdentifier,
            tbsCert.Add(PKCS7.AlgorithmIdentifier(oid));

            // TBSCertificate / Name
            tbsCert.Add(X501.FromString(issuer));

            // TBSCertificate / Validity
            ASN1 validity = tbsCert.Add(new ASN1(0x30));

            // TBSCertificate / Validity / Time
            validity.Add(ASN1Convert.FromDateTime(notBefore));
            // TBSCertificate / Validity / Time
            validity.Add(ASN1Convert.FromDateTime(notAfter));

            // TBSCertificate / Name
            tbsCert.Add(X501.FromString(subject));

            // TBSCertificate / SubjectPublicKeyInfo
            tbsCert.Add(SubjectPublicKeyInfo());

            if (version > 1)
            {
                // TBSCertificate / [1]  IMPLICIT UniqueIdentifier OPTIONAL
                if (issuerUniqueID != null)
                {
                    tbsCert.Add(new ASN1(0xA1, UniqueIdentifier(issuerUniqueID)));
                }

                // TBSCertificate / [2]  IMPLICIT UniqueIdentifier OPTIONAL
                if (subjectUniqueID != null)
                {
                    tbsCert.Add(new ASN1(0xA1, UniqueIdentifier(subjectUniqueID)));
                }

                // TBSCertificate / [3]  Extensions OPTIONAL
                if ((version > 2) && (extensions.Count > 0))
                {
                    tbsCert.Add(new ASN1(0xA3, extensions.GetBytes()));
                }
            }

            return(tbsCert);
        }
Exemplo n.º 2
0
            public byte[] GetBytes()
            {
                ASN1 aSN = new ASN1(48);

                aSN.Add(new ASN1(2, sn));
                aSN.Add(ASN1Convert.FromDateTime(revocationDate));
                if (extensions.Count > 0)
                {
                    aSN.Add(new ASN1(extensions.GetBytes()));
                }
                return(aSN.GetBytes());
            }
Exemplo n.º 3
0
            public byte[] GetBytes()
            {
                ASN1 sequence = new ASN1(0x30);

                sequence.Add(new ASN1(0x02, sn));
                sequence.Add(ASN1Convert.FromDateTime(revocationDate));
                if (extensions.Count > 0)
                {
                    sequence.Add(new ASN1(extensions.GetBytes()));
                }
                return(sequence.GetBytes());
            }
Exemplo n.º 4
0
        protected override ASN1 ToBeSigned(string oid)
        {
            ASN1 aSN = new ASN1(48);

            if (version > 1)
            {
                byte[] data = new byte[1]
                {
                    (byte)(version - 1)
                };
                ASN1 aSN2 = aSN.Add(new ASN1(160));
                aSN2.Add(new ASN1(2, data));
            }
            aSN.Add(new ASN1(2, sn));
            aSN.Add(PKCS7.AlgorithmIdentifier(oid));
            aSN.Add(X501.FromString(issuer));
            ASN1 aSN3 = aSN.Add(new ASN1(48));

            aSN3.Add(ASN1Convert.FromDateTime(notBefore));
            aSN3.Add(ASN1Convert.FromDateTime(notAfter));
            aSN.Add(X501.FromString(subject));
            aSN.Add(SubjectPublicKeyInfo());
            if (version > 1)
            {
                if (issuerUniqueID != null)
                {
                    aSN.Add(new ASN1(161, UniqueIdentifier(issuerUniqueID)));
                }
                if (subjectUniqueID != null)
                {
                    aSN.Add(new ASN1(161, UniqueIdentifier(subjectUniqueID)));
                }
                if (version > 2 && extensions.Count > 0)
                {
                    aSN.Add(new ASN1(163, extensions.GetBytes()));
                }
            }
            return(aSN);
        }