Exemplo n.º 1
0
        private BigInteger GetInteger(ASN1Sequence obj, int index)
        {
            SecurityAssert.SAssert(index >= 0 && index < obj.Elements.Count);

            var elem = obj.Elements[index];
            var intElem = elem as ASN1Integer;
            SecurityAssert.NotNull(intElem);

            return intElem.Value;
        }
Exemplo n.º 2
0
        public override byte[] GetBytes()
        {
            var asn1 = new ASN1Sequence(new[]
            {
                new ASN1Integer(Modulus),
                new ASN1Integer(Exponent),
            });

            using (var ms = new MemoryStream())
            {
                new DERWriter(ms).Write(asn1);

                return ms.ToArray();
            }
        }
Exemplo n.º 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)
            });
        }
Exemplo n.º 4
0
 public void Write(ASN1Sequence value)
 {
     WriteIdentifier(ASN1Class.Universal, true, ASN1UniversalTag.Sequence);
     WriteLength(value.ByteLength);
     WriteChildren(value);
 }
Exemplo n.º 5
0
 public void Write(ASN1Sequence value)
 {
     WriteIdentifier(ASN1Class.Universal, true, ASN1UniversalTag.Sequence);
     WriteLength(value.ByteLength);
     WriteChildren(value);
 }