private String generateCSR(X509Certificate cert, PrivateKey signingKey) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, KeyStoreException, IOException {
String sigalg = cert.getSigAlgName();
X509Name subject;
try{
ASN1InputStream ais = new ASN1InputStream(cert.getEncoded());
X509CertificateStructure x509Struct = new X509CertificateStructure((ASN1Sequence)ais.readObject());
ais.close();
subject = x509Struct.getSubject();
} catch(CertificateEncodingException e) {
log.warn(e.toString()+" while retrieving subject from certificate to create CSR. Using subjectDN instead.");
subject = new X509Name(cert.getSubjectDN().toString());
}
PublicKey publicKey = cert.getPublicKey();