public static String toPEMformat(X509Certificate[] certificateChain){
  StringWriter sw=new StringWriter();
  for (  X509Certificate certificate : certificateChain) {
    sw.append(toPEMformat(certificate));
  }
  return sw.toString();
}

public static String toPEMformat ( X509Certificate [ ] certificateChain ) { StringWriter sw = new StringWriter ( ) ; for ( X509Certificate certificate : certificateChain ) { sw . append ( toPEMformat ( certificate ) ) ; } return sw . toString ( ) ; }
serialize certificate chain in pem format
