sun.misc.HexDumpEncoder Java Examples

The following examples show how to use sun.misc.HexDumpEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ber.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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
        }
    }
}
 
Example #2
Source File: SignerInfo.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: CertId.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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()));
    }
}
 
Example #4
Source File: OutputRecord.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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) { }
    }
}
 
Example #5
Source File: X509CertImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #6
Source File: CertId.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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()));
    }
}
 
Example #7
Source File: CertId.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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()));
    }
}
 
Example #8
Source File: OutputRecord.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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) { }
    }
}
 
Example #9
Source File: CertId.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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()));
    }
}
 
Example #10
Source File: InputRecord.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: InputRecord.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: Ber.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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
        }
    }
}
 
Example #13
Source File: OutputRecord.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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) { }
    }
}
 
Example #14
Source File: X509CertImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #15
Source File: X509CertImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #16
Source File: SignerInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #17
Source File: X509CertImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #18
Source File: PBEParameters.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected String engineToString() {
    String LINE_SEP = System.getProperty("line.separator");
    String saltString = LINE_SEP + "    salt:" + LINE_SEP + "[";
    HexDumpEncoder encoder = new HexDumpEncoder();
    saltString += encoder.encodeBuffer(salt);
    saltString += "]";

    return saltString + LINE_SEP + "    iterationCount:"
        + LINE_SEP + Debug.toHexString(BigInteger.valueOf(iCount))
        + LINE_SEP;
}
 
Example #19
Source File: KeyIdentifier.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a printable representation of the KeyUsage.
 */
public String toString() {
    String s = "KeyIdentifier [\n";

    HexDumpEncoder encoder = new HexDumpEncoder();
    s += encoder.encodeBuffer(octetString);
    s += "]\n";
    return (s);
}
 
Example #20
Source File: KeyImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
    HexDumpEncoder hd = new HexDumpEncoder();
    return "EncryptionKey: keyType=" + keyType
                      + " keyBytes (hex dump)="
                      + (keyBytes == null || keyBytes.length == 0 ?
                         " Empty Key" :
                         '\n' + hd.encodeBuffer(keyBytes)
                      + '\n');


}
 
Example #21
Source File: BlockCipherParamsCore.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
    String LINE_SEP = System.getProperty("line.separator");

    String ivString = LINE_SEP + "    iv:" + LINE_SEP + "[";
    HexDumpEncoder encoder = new HexDumpEncoder();
    ivString += encoder.encodeBuffer(this.iv);
    ivString += "]" + LINE_SEP;
    return ivString;
}
 
Example #22
Source File: LDAPCertStore.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Collection<X509CertificatePair> getCertPairs(
    LDAPRequest request, String id) throws CertStoreException {

    /* fetch the encoded cert pairs from storage */
    byte[][] encodedCertPair;
    try {
        encodedCertPair = request.getValues(id);
    } catch (NamingException namingEx) {
        throw new CertStoreException(namingEx);
    }

    int n = encodedCertPair.length;
    if (n == 0) {
        return Collections.emptySet();
    }

    List<X509CertificatePair> certPairs = new ArrayList<>(n);
    /* decode each cert pair and add it to the Collection */
    for (int i = 0; i < n; i++) {
        try {
            X509CertificatePair certPair =
                X509CertificatePair.generateCertificatePair(encodedCertPair[i]);
            certPairs.add(certPair);
        } catch (CertificateException e) {
            if (debug != null) {
                debug.println(
                    "LDAPCertStore.getCertPairs() encountered exception "
                    + "while parsing cert, skipping the bad data: ");
                HexDumpEncoder encoder = new HexDumpEncoder();
                debug.println(
                    "[ " + encoder.encodeBuffer(encodedCertPair[i]) + " ]");
            }
        }
    }

    return certPairs;
}
 
Example #23
Source File: PolicyQualifierInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a printable representation of this
 * {@code PolicyQualifierInfo}.
 *
 * @return a {@code String} describing the contents of this
 *         {@code PolicyQualifierInfo}
 */
public String toString() {
    if (pqiString != null)
        return pqiString;
    HexDumpEncoder enc = new HexDumpEncoder();
    StringBuffer sb = new StringBuffer();
    sb.append("PolicyQualifierInfo: [\n");
    sb.append("  qualifierID: " + mId + "\n");
    sb.append("  qualifier: " +
        (mData == null ? "null" : enc.encodeBuffer(mData)) + "\n");
    sb.append("]");
    pqiString = sb.toString();
    return pqiString;
}
 
Example #24
Source File: PolicyQualifierInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a printable representation of this
 * {@code PolicyQualifierInfo}.
 *
 * @return a {@code String} describing the contents of this
 *         {@code PolicyQualifierInfo}
 */
public String toString() {
    if (pqiString != null)
        return pqiString;
    HexDumpEncoder enc = new HexDumpEncoder();
    StringBuffer sb = new StringBuffer();
    sb.append("PolicyQualifierInfo: [\n");
    sb.append("  qualifierID: " + mId + "\n");
    sb.append("  qualifier: " +
        (mData == null ? "null" : enc.encodeBuffer(mData)) + "\n");
    sb.append("]");
    pqiString = sb.toString();
    return pqiString;
}
 
Example #25
Source File: Handshaker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void printHex(HexDumpEncoder dump, byte[] bytes) {
    if (bytes == null) {
        System.out.println("(key bytes not available)");
    } else {
        try {
            dump.encodeBuffer(bytes, System.out);
        } catch (IOException e) {
            // just for debugging, ignore this
        }
    }
}
 
Example #26
Source File: OutputRecord.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void hashInternal(byte buf [], int offset, int len) {
    if (debug != null && Debug.isOn("data")) {
        try {
            HexDumpEncoder hd = new HexDumpEncoder();

            System.out.println("[write] MD5 and SHA1 hashes:  len = "
                + len);
            hd.encodeBuffer(new ByteArrayInputStream(buf,
                lastHashed, len), System.out);
        } catch (IOException e) { }
    }

    handshakeHash.update(buf, lastHashed, len);
    lastHashed = count;
}
 
Example #27
Source File: InputRecord.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void hashInternal(byte databuf [], int offset, int len) {
    if (debug != null && Debug.isOn("data")) {
        try {
            HexDumpEncoder hd = new HexDumpEncoder();

            System.out.println("[read] MD5 and SHA1 hashes:  len = "
                + len);
            hd.encodeBuffer(new ByteArrayInputStream(databuf, offset, len),
                System.out);
        } catch (IOException e) { }
    }
    handshakeHash.update(databuf, offset, len);
}
 
Example #28
Source File: X509Key.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String toString()
{
    HexDumpEncoder  encoder = new HexDumpEncoder();

    return "algorithm = " + algid.toString()
        + ", unparsed keybits = \n" + encoder.encodeBuffer(key);
}
 
Example #29
Source File: PolicyQualifierInfo.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Return a printable representation of this
 * {@code PolicyQualifierInfo}.
 *
 * @return a {@code String} describing the contents of this
 *         {@code PolicyQualifierInfo}
 */
public String toString() {
    if (pqiString != null)
        return pqiString;
    HexDumpEncoder enc = new HexDumpEncoder();
    StringBuffer sb = new StringBuffer();
    sb.append("PolicyQualifierInfo: [\n");
    sb.append("  qualifierID: " + mId + "\n");
    sb.append("  qualifier: " +
        (mData == null ? "null" : enc.encodeBuffer(mData)) + "\n");
    sb.append("]");
    pqiString = sb.toString();
    return pqiString;
}
 
Example #30
Source File: BlockCipherParamsCore.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
    String LINE_SEP = System.getProperty("line.separator");

    String ivString = LINE_SEP + "    iv:" + LINE_SEP + "[";
    HexDumpEncoder encoder = new HexDumpEncoder();
    ivString += encoder.encodeBuffer(this.iv);
    ivString += "]" + LINE_SEP;
    return ivString;
}