publicclassHandler{ publicstaticvoidmain(String[] args){ // Prompt the user to input certificate name System.out.print("Please input the certificate: "); Scanner input = new Scanner(System.in); String certificatePath = input.next();
Certificate c = null; String s; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); // Read Certification FileInputStream in = new FileInputStream(certificatePath); c = cf.generateCertificate(in); in.close();
s = c.toString();
// Output as a txt file FileOutputStream fout = new FileOutputStream("tmp.txt"); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fout)); out.write(s, 0, s.length()); out.close(); } catch (Exception ex) { ex.printStackTrace(); }
byte[] by = t.getExtensionValue("2.5.29.32"); String str = new String(by); System.out.println(str); }
privatestatic String stringFormat(String str, int format, int space){ String spaceStr = ""; for (int i = 0; i < space; i++) { spaceStr += " "; } String result = spaceStr;
for (int i = 0; i < str.length()-1;) { result += str.charAt(i); i++; result += str.charAt(i); i++; if (i == str.length()) { break; } elseif (i != 0 && i % format == 0) { result += ":\n"; result += spaceStr; } elseif (i % 2 == 0) { result += ":"; } } return result; } }