private static void formatString(final Integer index, final boolean verbose, final StringBuilder sb, final X509Certificate cert) { String subject = X509Util.getRfc4519Name(cert.getSubjectX500Principal()); sb.append("\t\tCertificate"); if (index != null) { sb.append("[").append(index).append("]"); } sb.append(": "); if (!verbose) { sb.append(subject).append("\n"); return; } else { sb.append("\n"); } sb.append("\t\t\tSubject: ").append(subject).append("\n"); String issuer = X509Util.getRfc4519Name(cert.getIssuerX500Principal()); sb.append("\t\t\tIssuer: ").append(issuer).append("\n"); sb.append("\t\t\tSerial: ").append(LogUtil.formatCsn(cert.getSerialNumber())).append("\n"); sb.append("\t\t\tStart time: ").append(cert.getNotBefore()).append("\n"); sb.append("\t\t\tEnd time: ").append(cert.getNotAfter()).append("\n"); sb.append("\t\t\tSHA1 Sum: "); try { sb.append(HashAlgoType.SHA1.hexHash(cert.getEncoded())); } catch (CertificateEncodingException ex) { sb.append("ERROR"); } sb.append("\n"); }
private static void savePkcs11Entry(final File dir, final byte[] id, final String label, final byte[] value) throws P11TokenException { ParamUtil.requireNonNull("dir", dir); ParamUtil.requireNonNull("id", id); ParamUtil.requireNonBlank("label", label); ParamUtil.requireNonNull("value", value); String hexId = Hex.toHexString(id).toLowerCase(); StringBuilder sb = new StringBuilder(200); sb.append(PROP_ID).append('=').append(hexId).append('\n'); sb.append(PROP_LABEL).append('=').append(label).append('\n'); sb.append(PROP_SHA1SUM).append('=').append(HashAlgoType.SHA1.hexHash(value)).append('\n'); try { IoUtil.save(new File(dir, hexId + INFO_FILE_SUFFIX), sb.toString().getBytes()); IoUtil.save(new File(dir, hexId + VALUE_FILE_SUFFIX), value); } catch (IOException ex) { throw new P11TokenException("could not save certificate"); } }
public EjbcaCaInfo(final int caId, final byte[] certBytes, final String caDirname) { ParamUtil.requireNonNull("certBytes", certBytes); this.caId = caId; this.hexSha1 = HashAlgoType.SHA1.hexHash(certBytes).toLowerCase(); this.subject = Certificate.getInstance(certBytes).getSubject(); this.caDirname = ParamUtil.requireNonNull("caDirname", caDirname); }
public void setCertificate(final X509Certificate certificate) throws CaMgmtException { if (certificate == null) { this.cert = null; this.subject = null; this.hexSha1OfCert = null; } else { if (!X509Util.hasKeyusage(certificate, KeyUsage.keyCertSign)) { throw new CaMgmtException("CA certificate does not have keyusage keyCertSign"); } this.cert = certificate; this.subject = X509Util.getRfc4519Name(certificate.getSubjectX500Principal()); byte[] encodedCert; try { encodedCert = certificate.getEncoded(); } catch (CertificateEncodingException ex) { throw new CaMgmtException("could not encoded certificate", ex); } this.hexSha1OfCert = HashAlgoType.SHA1.hexHash(encodedCert); } }
byte[] certBytes = Base64.decodeFast(b64Cert); String sha1Cert = HashAlgoType.SHA1.hexHash(certBytes);
byte[] certBytes = Base64.decodeFast(b64Cert); String sha1 = HashAlgoType.SHA1.hexHash(certBytes); String certFileName = sha1 + ".der"; if (!evaulateOnly) { continue; String sha1 = HashAlgoType.SHA1.hexHash(crlBytes); String b64Data = rs.getString("DATA"); byte[] dataBytes = Base64.decodeFast(b64Data); String sha1 = HashAlgoType.SHA1.hexHash(dataBytes); final String dataFilename = sha1 + ".req"; if (!evaulateOnly) {