示例#1
0
        public X509Certificate AddSubjectAltNames(params string[] names)
        {
            var ext = Tbs.Extensions.FirstOrDefault(e => e.Id == Asn1ObjectIdentifier.SubjectAltName);

            if (ext == null)
            {
                ext = new X509Extension {
                    Id = Asn1ObjectIdentifier.SubjectAltName
                };
                Tbs.Extensions.Add(ext);
            }
            var val  = ext.Value;
            var node = val != null && val.Length != 0 ? Asn1Sequence.ReadFrom(val) : new Asn1Sequence();

            foreach (var name in names)
            {
                node.Nodes.Add(new Asn1CustomNode(2, Asn1TagForm.Primitive, Asn1TagClass.ContextDefined)
                {
                    Data = Encoding.UTF8.GetBytes(name)
                });
            }

            ext.Value = node.GetBytes();
            return(this);
        }