Пример #1
0
  /**
   * Create dummy public key certificate.
   *
   * @param keyId key id
   * @param cn common name
   * @throws Exception if an error occurs
   */
  @Command(description = "Create dummy public key certificate")
  public void dummyCert(
      @Param(name = "keyId", description = "Key ID") String keyId,
      @Param(name = "cn", description = "Common name") String cn)
      throws Exception {
    Calendar cal = GregorianCalendar.getInstance();
    cal.add(Calendar.YEAR, -1);
    Date notBefore = cal.getTime();
    cal.add(Calendar.YEAR, 2);
    Date notAfter = cal.getTime();

    ClientId memberId = ClientId.create("FOO", "BAR", "BAZ");

    GenerateSelfSignedCert request =
        new GenerateSelfSignedCert(keyId, cn, notBefore, notAfter, KeyUsageInfo.SIGNING, memberId);

    GenerateSelfSignedCertResponse response = SignerClient.execute(request);
    X509Certificate cert = readCertificate(response.getCertificateBytes());

    System.out.println("Certificate base64:");
    System.out.println(encodeBase64(cert.getEncoded()));
    bytesToFile(keyId + ".crt", cert.getEncoded());
    base64ToFile(keyId + ".crt.b64", cert.getEncoded());
  }