// 自己署名証明書の作成 public Certificate(PrivKey selfSignKey, CertificateOptions options) { X509Name name = options.GenerateName(); X509V3CertificateGenerator gen = new X509V3CertificateGenerator(); gen.SetSerialNumber(new BigInteger(options.Serial.ToArray())); gen.SetIssuerDN(name); gen.SetSubjectDN(name); gen.SetNotBefore(DateTime.Now.AddDays(-1)); gen.SetNotAfter(options.Expires.UtcDateTime); gen.SetPublicKey(selfSignKey.PublicKey.PublicKeyData); X509Extension extConst = new X509Extension(true, new DerOctetString(new BasicConstraints(true))); gen.AddExtension(X509Extensions.BasicConstraints, true, extConst.GetParsedValue()); X509Extension extBasicUsage = new X509Extension(false, new DerOctetString(new KeyUsage(options.KeyUsages))); gen.AddExtension(X509Extensions.KeyUsage, false, extBasicUsage.GetParsedValue()); X509Extension extExtendedUsage = new X509Extension(false, new DerOctetString(new ExtendedKeyUsage(options.ExtendedKeyUsages))); gen.AddExtension(X509Extensions.ExtendedKeyUsage, false, extExtendedUsage.GetParsedValue()); X509Extension altName = new X509Extension(false, new DerOctetString(options.GenerateAltNames())); gen.AddExtension(X509Extensions.SubjectAlternativeName, false, altName.GetParsedValue()); this.CertData = gen.Generate(new Asn1SignatureFactory(options.GetSignatureAlgorithmOid(), selfSignKey.PrivateKeyData.Private, PkiUtil.NewSecureRandom())); InitFields(); }
public Csr(PrivKey priv, CertificateOptions options) { X509Name subject = options.GenerateName(); GeneralNames alt = options.GenerateAltNames(); X509Extension altName = new X509Extension(false, new DerOctetString(alt)); List <object> oids = new List <object>() { X509Extensions.SubjectAlternativeName, }; List <object> values = new List <object>() { altName, }; X509Extensions x509exts = new X509Extensions(oids, values); X509Attribute attr = new X509Attribute(PkcsObjectIdentifiers.Pkcs9AtExtensionRequest.Id, new DerSet(x509exts)); AttributePkcs attr2 = new AttributePkcs(PkcsObjectIdentifiers.Pkcs9AtExtensionRequest, new DerSet(x509exts)); this.Request = new Pkcs10CertificationRequest(new Asn1SignatureFactory(options.GetSignatureAlgorithmOid(), priv.PrivateKeyData.Private, PkiUtil.NewSecureRandom()), subject, priv.PublicKey.PublicKeyData, new DerSet(attr2)); }