示例#1
0
        public void Write(ASN1Integer value)
        {
            WriteIdentifier(ASN1Class.Universal, false, ASN1UniversalTag.Integer);
            WriteLength(value.ByteLength);

            var buffer = value.Value.ToByteArray();
            // convert to big endian
            Array.Reverse(buffer);

            writer.Write(buffer);
        }
示例#2
0
        public void Write(ASN1Integer value)
        {
            WriteIdentifier(ASN1Class.Universal, false, ASN1UniversalTag.Integer);
            WriteLength(value.ByteLength);

            var buffer = value.Value.ToByteArray();

            // convert to big endian
            Array.Reverse(buffer);

            _writer.Write(buffer);
        }
示例#3
0
        private ASN1Object GetASN1(X509Certificate cert)
        {
            var version = new ASN1Integer(cert.Version - 1);
            var taggedVersion = new ASN1Tagged(0, new[] { version });
            var serialNumber = new ASN1Integer(cert.SerialNumber);
            var signatureAlgo = GetAlgorithmIdentifier(cert.SignatureAlgorithm);
            var issuer = GetName(cert.Issuer);
            var validity = GetValidity(cert.Validity);
            var subject = GetName(cert.Subject);
            var subjectPublicKeyInfo = new ASN1Sequence(new[]
            {
                GetAlgorithmIdentifier(cert.SubjectPublicKeyAlgorithm),
                new ASN1BitString(cert.SubjectPublicKey.GetBytes())
            });

            var tbs = new List<ASN1Object>
            {
                taggedVersion,
                serialNumber,
                signatureAlgo,
                issuer,
                validity,
                subject,
                subjectPublicKeyInfo
            };

            if (cert.Version >= 2)
            {
                //TODO issuerUniqueID  
                //TODO subjectUniqueID 
            }

            if (cert.Version >= 3)
            {
                var extensions = GetExtensions(cert.Extensions);
                var taggedExtensions = new ASN1Tagged(3, new[] { extensions });
                tbs.Add(taggedExtensions);
            }

            return new ASN1Sequence(new List<ASN1Object>
            {
                new ASN1Sequence(tbs),
                signatureAlgo,
                new ASN1BitString(cert.Signature)
            });
        }