use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class Certificate method main.
public static void main(String[] argv) {
try {
if (argv.length > 2 || argv.length < 1) {
System.out.println("Usage: Certificate <dbdir> [<certfile>]");
System.exit(0);
}
CryptoManager.initialize(argv[0]);
CryptoManager cm = CryptoManager.getInstance();
Certificate cert;
// read in a cert
FileInputStream fis = new FileInputStream(argv[1]);
try (BufferedInputStream bis = new BufferedInputStream(fis)) {
cert = (Certificate) Certificate.getTemplate().decode(bis);
}
CertificateInfo info = cert.getInfo();
info.print(System.out);
// X509Certificate hardcore = cm.findCertByNickname("Hardcore");
// PublicKey key = hardcore.getPublicKey();
cert.verify();
System.out.println("verified");
FileOutputStream fos = new FileOutputStream("certinfo.der");
info.encode(fos);
fos.close();
// make a new public key
CryptoToken token = cm.getInternalKeyStorageToken();
KeyPairGenerator kpg = token.getKeyPairGenerator(KeyPairAlgorithm.RSA);
kpg.initialize(512);
System.out.println("Generating a new key pair...");
KeyPair kp = kpg.genKeyPair();
System.out.println("Generated key pair");
// set the certificate's public key
info.setSubjectPublicKeyInfo(kp.getPublic());
// increment serial number
int newSerial = info.getSerialNumber().intValue() + 1;
info.setSerialNumber(new INTEGER(newSerial));
// make new Name
Name name = new Name();
name.addCommonName("Stra\u00dfenverk\u00e4ufer 'R' Us");
name.addCountryName("US");
name.addOrganizationName("Some Corporation");
name.addOrganizationalUnitName("some org unit?");
name.addLocalityName("Silicon Valley");
name.addStateOrProvinceName("California");
info.setIssuer(name);
info.setSubject(name);
// set validity
Calendar cal = Calendar.getInstance();
cal.set(1997, Calendar.APRIL, 1);
info.setNotBefore(cal.getTime());
cal.set(2010, Calendar.APRIL, 1);
info.setNotAfter(cal.getTime());
System.out.println("About to create a new cert...");
// create a new cert from this certinfo
Certificate genCert = new Certificate(info, kp.getPrivate(), SignatureAlgorithm.RSASignatureWithMD5Digest);
System.out.println("Created new cert");
genCert.verify();
System.out.println("Cert verifies!");
fos = new FileOutputStream("gencert.der");
genCert.encode(fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class BodyPartReference method addBodyPartId.
/**
* Adds a BodyPartID to the bodyPartPath SEQUENCE.
*/
public void addBodyPartId(int id) {
INTEGER id1 = new INTEGER(id);
assert (id1.compareTo(BODYIDMAX) <= 0);
bodyPartPath.addElement(id1);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class CertificateInfo method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
if (version != v1) {
// v1 is the default
seq.addElement(new EXPLICIT(new Tag(0), new INTEGER(version.getNumber())));
}
seq.addElement(serialNumber);
seq.addElement(signatureAlgId);
seq.addElement(issuer);
SEQUENCE validity = new SEQUENCE();
validity.addElement(encodeValidityDate(notBefore));
validity.addElement(encodeValidityDate(notAfter));
seq.addElement(validity);
seq.addElement(subject);
seq.addElement(subjectPublicKeyInfo);
if (issuerUniqueIdentifier != null) {
seq.addElement(new Tag(1), issuerUniqueIdentifier);
}
if (subjectUniqueIdentifier != null) {
seq.addElement(new Tag(2), subjectUniqueIdentifier);
}
if (extensions.size() > 0) {
seq.addElement(new EXPLICIT(new Tag(3), extensions));
}
seq.encode(implicitTag, ostream);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class CMCStatusInfoV2 method addBodyPartID.
/**
* Adds a BodyPartID to the bodyList SEQUENCE.
*/
public void addBodyPartID(int id) {
INTEGER id1 = new INTEGER(id);
assert (id1.compareTo(BODYIDMAX) <= 0);
bodyList.addElement(id1);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class MacData method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(mac);
seq.addElement(macSalt);
if (!macIterationCount.equals(new INTEGER(DEFAULT_ITERATIONS))) {
// 1 is the default, only include this element if it is not
// the default
seq.addElement(macIterationCount);
}
seq.encode(implicitTag, ostream);
}
Aggregations