/** * Returns a printable representation of the certificate. This does not * contain all the information available to distinguish this from any * other certificate. The certificate must be fully constructed * before this function may be called. */ public String toString() { if (info == null || algId == null || signature == null) return ""; StringBuilder sb = new StringBuilder(); sb.append("[\n"); sb.append(info.toString() + "\n"); sb.append(" Algorithm: [" + algId.toString() + "]\n"); HexDumpEncoder encoder = new HexDumpEncoder(); sb.append(" Signature:\n" + encoder.encodeBuffer(signature)); sb.append("\n]"); return sb.toString(); }
private int readFully(InputStream s, byte b[], int off, int len) throws IOException { int n = 0; while (n < len) { int readLen = s.read(b, off + n, len - n); if (readLen < 0) { return readLen; } if (debug != null && Debug.isOn("packet")) { try { HexDumpEncoder hd = new HexDumpEncoder(); ByteBuffer bb = ByteBuffer.wrap(b, off + n, readLen); System.out.println("[Raw read]: length = " + bb.remaining()); hd.encodeBuffer(bb, System.out); } catch (IOException e) { } } n += readLen; exlen += readLen; } return n; }
void writeBuffer(OutputStream s, byte [] buf, int off, int len, int debugOffset) throws IOException { s.write(buf, off, len); s.flush(); // Output only the record from the specified debug offset. if (debug != null && Debug.isOn("packet")) { try { HexDumpEncoder hd = new HexDumpEncoder(); System.out.println("[Raw write]: length = " + (len - debugOffset)); hd.encodeBuffer(new ByteArrayInputStream(buf, off + debugOffset, len - debugOffset), System.out); } catch (IOException e) { } } }
private void dumpPacket(EngineArgs ea, boolean hsData) { try { HexDumpEncoder hd = new HexDumpEncoder(); ByteBuffer bb = ea.netData.duplicate(); int pos = bb.position(); bb.position(pos - ea.deltaNet()); bb.limit(pos); System.out.println("[Raw write" + (hsData ? "" : " (bb)") + "]: length = " + bb.remaining()); hd.encodeBuffer(bb, System.out); } catch (IOException e) { } }
public String toString() { HexDumpEncoder hexDump = new HexDumpEncoder(); String out = ""; out += "Signer Info for (issuer): " + issuerName + "\n"; out += "\tversion: " + Debug.toHexString(version) + "\n"; out += "\tcertificateSerialNumber: " + Debug.toHexString(certificateSerialNumber) + "\n"; out += "\tdigestAlgorithmId: " + digestAlgorithmId + "\n"; if (authenticatedAttributes != null) { out += "\tauthenticatedAttributes: " + authenticatedAttributes + "\n"; } out += "\tdigestEncryptionAlgorithmId: " + digestEncryptionAlgorithmId + "\n"; out += "\tencryptedDigest: " + "\n" + hexDump.encodeBuffer(encryptedDigest) + "\n"; if (unauthenticatedAttributes != null) { out += "\tunauthenticatedAttributes: " + unauthenticatedAttributes + "\n"; } return out; }
/** * Encode the CertId using ASN.1 DER. * The hash algorithm used is SHA-1. */ public void encode(DerOutputStream out) throws IOException { DerOutputStream tmp = new DerOutputStream(); hashAlgId.encode(tmp); tmp.putOctetString(issuerNameHash); tmp.putOctetString(issuerKeyHash); certSerialNumber.encode(tmp); out.write(DerValue.tag_Sequence, tmp); if (debug) { HexDumpEncoder encoder = new HexDumpEncoder(); System.out.println("Encoded certId is " + encoder.encode(out.toByteArray())); } }
public static void dumpBER(OutputStream outStream, String tag, byte[] bytes, int from, int to) { try { outStream.write('\n'); outStream.write(tag.getBytes("UTF8")); new HexDumpEncoder().encodeBuffer( new ByteArrayInputStream(bytes, from, to), outStream); outStream.write('\n'); } catch (IOException e) { try { outStream.write( "Ber.dumpBER(): error encountered\n".getBytes("UTF8")); } catch (IOException e2) { // ignore } } }
public CertId(X500Principal issuerName, PublicKey issuerKey, SerialNumber serialNumber) throws IOException { // compute issuerNameHash MessageDigest md = null; try { md = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException nsae) { throw new IOException("Unable to create CertId", nsae); } hashAlgId = SHA1_ALGID; md.update(issuerName.getEncoded()); issuerNameHash = md.digest(); // compute issuerKeyHash (remove the tag and length) byte[] pubKey = issuerKey.getEncoded(); DerValue val = new DerValue(pubKey); DerValue[] seq = new DerValue[2]; seq[0] = val.data.getDerValue(); // AlgorithmID seq[1] = val.data.getDerValue(); // Key byte[] keyBytes = seq[1].getBitString(); md.update(keyBytes); issuerKeyHash = md.digest(); certSerialNumber = serialNumber; if (debug) { HexDumpEncoder encoder = new HexDumpEncoder(); System.out.println("Issuer Name is " + issuerName); System.out.println("issuerNameHash is " + encoder.encodeBuffer(issuerNameHash)); System.out.println("issuerKeyHash is " + encoder.encodeBuffer(issuerKeyHash)); System.out.println("SerialNumber is " + serialNumber.getNumber()); } }