/** * generate an X509 certificate, based on the current issuer and subject, using the passed in * provider for the signing and the supplied source of randomness, if required. */ public X509AttributeCertificate generate(PrivateKey key, String provider, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { if (!extGenerator.isEmpty()) { acInfoGen.setExtensions(extGenerator.generate()); } AttributeCertificateInfo acInfo = acInfoGen.generateAttributeCertificateInfo(); ASN1EncodableVector v = new ASN1EncodableVector(); v.add(acInfo); v.add(sigAlgId); try { v.add( new DERBitString( X509Util.calculateSignature( sigOID, signatureAlgorithm, provider, key, random, acInfo))); return new X509V2AttributeCertificate(new AttributeCertificate(new DERSequence(v))); } catch (IOException e) { throw new ExtCertificateEncodingException("constructed invalid certificate", e); } }
/** * Set the signature algorithm. This can be either a name or an OID, names are treated as case * insensitive. * * @param signatureAlgorithm string representation of the algorithm name. */ public void setSignatureAlgorithm(String signatureAlgorithm) { this.signatureAlgorithm = signatureAlgorithm; try { sigOID = X509Util.getAlgorithmOID(signatureAlgorithm); } catch (Exception e) { throw new IllegalArgumentException("Unknown signature type requested"); } sigAlgId = X509Util.getSigAlgID(sigOID, signatureAlgorithm); acInfoGen.setSignature(sigAlgId); }
/** add an attribute */ public void addAttribute(X509Attribute attribute) { acInfoGen.addAttribute(Attribute.getInstance(attribute.toASN1Object())); }
public void setNotAfter(Date date) { acInfoGen.setEndDate(new DERGeneralizedTime(date)); }
public void setNotBefore(Date date) { acInfoGen.setStartDate(new DERGeneralizedTime(date)); }
/** set the serial number for the certificate. */ public void setSerialNumber(BigInteger serialNumber) { acInfoGen.setSerialNumber(new DERInteger(serialNumber)); }
/** Set the issuer */ public void setIssuer(AttributeCertificateIssuer issuer) { acInfoGen.setIssuer(AttCertIssuer.getInstance(issuer.form)); }
/** Set the Holder of this Attribute Certificate */ public void setHolder(AttributeCertificateHolder holder) { acInfoGen.setHolder(holder.holder); }