final String pubKeyPEM =
certToPEMString(Base64.encode(cert.getEncoded()));
final OpenSSLKey k = new BouncyCastleOpenSSLKey(keyPair.getPrivate());
final StringWriter writer = new StringWriter();
k.writeTo(writer);
final String privKeyPEM = writer.toString();
final FileWriter pubFile = new FileWriter(pubpath);
final FileWriter privFile = new FileWriter(privpath);