X509 { public static X509Certificate generateV1Cert(KeyPair pair) throws Exception { X509V1CertificateGenerator certGen = new X509V1CertificateGenerator(); certGen.setSerialNumber(BigInteger.valueOf(1)); certGen.setIssuerDN(new X500Principal("CN=ebay")); certGen.setNotBefore(new Date(System.currentTimeMillis())); certGen.setNotAfter(new Date(System.currentTimeMillis() + VALIDITY_PERIOD)); certGen.setSubjectDN(new X500Principal("CN=npesic@ebay.com")); certGen.setPublicKey(pair.getPublic()); certGen.setSignatureAlgorithm("SHA1WithECDSA"); return certGen.generate(pair.getPrivate(), "BC"); }  static X509Certificate parseDer(byte[] derEncodedCert); static X509Certificate parseDer(InputStream is); static X509Certificate generateV3Cert(KeyPair pair); static X509Certificate generateV1Cert(KeyPair pair);  }
@Test public void certV1Creation() throws Exception { KeyPair keyPair = KeyCodec.generate(); X509Certificate x509Certificate = X509.generateV1Cert(keyPair); assertNotNull(x509Certificate); logger.info("V1 : "+x509Certificate.toString()); logger.info("Base64 of DER encoding : "+ Base64.encodeBase64URLSafeString(x509Certificate.getEncoded())); logger.info("Pub : "+Base64.encodeBase64URLSafeString(keyPair.getPublic().getEncoded())); logger.info("Priv : "+Base64.encodeBase64URLSafeString(keyPair.getPrivate().getEncoded())); }