sun.security.util.HexDumpEncoder Java Examples

The following examples show how to use sun.security.util.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: DTLSOverDatagram.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
final static void printHex(String prefix,
        byte[] bytes, int offset, int length) {

    HexDumpEncoder  dump = new HexDumpEncoder();

    synchronized (System.out) {
        System.out.println(prefix);
        try {
            ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
            dump.encodeBuffer(bb, System.out);
        } catch (Exception e) {
            // ignore
        }
        System.out.flush();
    }
}
 
Example #2
Source File: CertificateVerify.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"CertificateVerify\": '{'\n" +
            "  \"signature algorithm\": {0}\n" +
            "  \"signature\": '{'\n" +
            "{1}\n" +
            "  '}'\n" +
            "'}'",
            Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        signatureScheme.name,
        Utilities.indent(
                hexEncoder.encodeBuffer(signature), "    ")
    };

    return messageFormat.format(messageFields);
}
 
Example #3
Source File: DHClientKeyExchange.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\"DH ClientKeyExchange\": '{'\n" +
        "  \"parameters\": '{'\n" +
        "    \"dh_Yc\": '{'\n" +
        "{0}\n" +
        "    '}',\n" +
        "  '}'\n" +
        "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        Utilities.indent(
                hexEncoder.encodeBuffer(y), "      "),
    };
    return messageFormat.format(messageFields);
}
 
Example #4
Source File: KeyShareExtension.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\n'{'\n" +
        "  \"named group\": {0}\n" +
        "  \"key_exchange\": '{'\n" +
        "{1}\n" +
        "  '}'\n" +
        "'}',", Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        NamedGroup.nameOf(namedGroupId),
        Utilities.indent(hexEncoder.encode(keyExchange), "    ")
    };

    return messageFormat.format(messageFields);
}
 
Example #5
Source File: CertificateVerify.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"CertificateVerify\": '{'\n" +
            "  \"signature\": '{'\n" +
            "{0}\n" +
            "  '}'\n" +
            "'}'",
            Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        Utilities.indent(
                hexEncoder.encodeBuffer(signature), "    ")
    };

    return messageFormat.format(messageFields);
}
 
Example #6
Source File: CertificateVerify.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"CertificateVerify\": '{'\n" +
            "  \"signature\": '{'\n" +
            "{0}\n" +
            "  '}'\n" +
            "'}'",
            Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        Utilities.indent(
                hexEncoder.encodeBuffer(signature), "    ")
    };

    return messageFormat.format(messageFields);
}
 
Example #7
Source File: Finished.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"Finished\": '{'\n" +
            "  \"verify data\": '{'\n" +
            "{0}\n" +
            "  '}'" +
            "'}'",
            Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
            Utilities.indent(hexEncoder.encode(verifyData), "    "),
        };
    return messageFormat.format(messageFields);
}
 
Example #8
Source File: CertificateVerify.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"CertificateVerify\": '{'\n" +
            "  \"signature algorithm\": {0}\n" +
            "  \"signature\": '{'\n" +
            "{1}\n" +
            "  '}'\n" +
            "'}'",
            Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        signatureScheme.name,
        Utilities.indent(
                hexEncoder.encodeBuffer(signature), "    ")
    };

    return messageFormat.format(messageFields);
}
 
Example #9
Source File: KeyShareExtension.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\"server_share\": '{'\n" +
        "  \"named group\": {0}\n" +
        "  \"key_exchange\": '{'\n" +
        "{1}\n" +
        "  '}'\n" +
        "'}',", Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        NamedGroup.nameOf(serverShare.namedGroupId),
        Utilities.indent(
                hexEncoder.encode(serverShare.keyExchange), "    ")
    };

    return messageFormat.format(messageFields);
}
 
Example #10
Source File: RSAClientKeyExchange.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\"RSA ClientKeyExchange\": '{'\n" +
        "  \"client_version\":  {0}\n" +
        "  \"encncrypted\": '{'\n" +
        "{1}\n" +
        "  '}'\n" +
        "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        ProtocolVersion.nameOf(protocolVersion),
        Utilities.indent(
                hexEncoder.encodeBuffer(encrypted), "    "),
    };
    return messageFormat.format(messageFields);
}
 
Example #11
Source File: SessionTicketExtension.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    if (data == null) {
        return "<null>";
    }
    if (data.capacity() == 0) {
        return "<empty>";
    }

    MessageFormat messageFormat = new MessageFormat(
            "  \"ticket\" : '{'\n" +
                    "{0}\n" +
                    "  '}'",
            Locale.ENGLISH);
    HexDumpEncoder hexEncoder = new HexDumpEncoder();

    Object[] messageFields = {
            Utilities.indent(hexEncoder.encode(data.duplicate()),
                    "    "),
    };

    return messageFormat.format(messageFields);
}
 
Example #12
Source File: CertStatusExtension.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\"certificate status type\": {0}\n" +
        "\"encoded certificate status\": '{'\n" +
        "{1}\n" +
        "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    String encoded = hexEncoder.encodeBuffer(encodedRequest);

    Object[] messageFields = {
        CertStatusRequestType.nameOf(statusType),
        Utilities.indent(encoded)
    };

    return messageFormat.format(messageFields);
}
 
Example #13
Source File: SSLExtensions.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private static String toString(int extId, byte[] extData) {
    MessageFormat messageFormat = new MessageFormat(
        "\"unknown extension ({0})\": '{'\n" +
        "{1}\n" +
        "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    String encoded = hexEncoder.encodeBuffer(extData);

    Object[] messageFields = {
        extId,
        Utilities.indent(encoded)
    };

    return messageFormat.format(messageFields);
}
 
Example #14
Source File: NewSessionTicket.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"NewSessionTicket\": '{'\n" +
                    "  \"ticket_lifetime\"      : \"{0}\",\n" +
                    "  \"ticket\"               : '{'\n" +
                    "{1}\n" +
                    "  '}'" +
                    "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
            ticketLifetime,
            Utilities.indent(hexEncoder.encode(ticket), "    "),
    };
    return messageFormat.format(messageFields);
}
 
Example #15
Source File: SignerInfo.java    From Bytecoder with Apache License 2.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 #16
Source File: AbstractHashDrbg.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
protected void reseedAlgorithm(
        byte[] ei,
        byte[] additionalInput) {
    if (debug != null) {
        debug.println(this, "reseedAlgorithm\n" +
                new HexDumpEncoder().encodeBuffer(ei) + "\n" +
                ((additionalInput == null) ? "" :
                    new HexDumpEncoder().encodeBuffer(additionalInput)));
    }

    // 800-90Ar1 10.1.1.3: Hash_DRBG Reseed Process.
    // 800-90Ar1 10.1.2.4: Hmac_DRBG Reseed Process.

    // Step 1: entropy_input || additional_input.
    List<byte[]> inputs = new ArrayList<>(2);
    inputs.add(ei);
    if (additionalInput != null) {
        inputs.add(additionalInput);
    }
    hashReseedInternal(inputs);
}
 
Example #17
Source File: CertId.java    From Bytecoder with Apache License 2.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 #18
Source File: SignerInfo.java    From openjdk-jdk9 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 #19
Source File: AbstractHashDrbg.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void reseedAlgorithm(
        byte[] ei,
        byte[] additionalInput) {
    if (debug != null) {
        debug.println(this, "reseedAlgorithm\n" +
                new HexDumpEncoder().encodeBuffer(ei) + "\n" +
                ((additionalInput == null) ? "" :
                    new HexDumpEncoder().encodeBuffer(additionalInput)));
    }

    // 800-90Ar1 10.1.1.3: Hash_DRBG Reseed Process.
    // 800-90Ar1 10.1.2.4: Hmac_DRBG Reseed Process.

    // Step 1: entropy_input || additional_input.
    List<byte[]> inputs = new ArrayList<>(2);
    inputs.add(ei);
    if (additionalInput != null) {
        inputs.add(additionalInput);
    }
    hashReseedInternal(inputs);
}
 
Example #20
Source File: CertId.java    From openjdk-jdk9 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 #21
Source File: CertStatusExtension.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\"certificate status response type\": {0}\n" +
        "\"encoded certificate status\": '{'\n" +
        "{1}\n" +
        "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    String encoded = hexEncoder.encodeBuffer(encodedResponse);

    Object[] messageFields = {
        CertStatusRequestType.nameOf(statusType),
        Utilities.indent(encoded)
    };

    return messageFormat.format(messageFields);
}
 
Example #22
Source File: Ber.java    From openjdk-jdk9 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 #23
Source File: ClientHelloChromeInterOp.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected byte[] createClientHelloMessage() {
    byte[] bytes = Base64.getMimeDecoder().decode(ClientHelloMsg);

    // Dump the hex codes of the ClientHello message so that developers
    // can easily check whether the message is captured correct or not.
    HexDumpEncoder dump = new HexDumpEncoder();
    System.out.println("The ClientHello message used");
    try {
        dump.encodeBuffer(bytes, System.out);
    } catch (Exception e) {
        // ignore
    }

    return bytes;
}
 
Example #24
Source File: DTLSOverDatagram.java    From SigFW with GNU Affero General Public License v3.0 6 votes vote down vote up
final static void printHex(String prefix,
        byte[] bytes, int offset, int length) {

    HexDumpEncoder  dump = new HexDumpEncoder();

    synchronized (System.out) {
        System.out.println(prefix);
        try {
            ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
            dump.encodeBuffer(bb, System.out);
        } catch (Exception e) {
            // ignore
        }
        System.out.flush();
    }
}
 
Example #25
Source File: KeyImpl.java    From openjdk-jdk9 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 #26
Source File: CertId.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a string representation of the CertId.
 */
@Override public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("CertId \n");
    sb.append("Algorithm: " + hashAlgId.toString() +"\n");
    sb.append("issuerNameHash \n");
    HexDumpEncoder encoder = new HexDumpEncoder();
    sb.append(encoder.encode(issuerNameHash));
    sb.append("\nissuerKeyHash: \n");
    sb.append(encoder.encode(issuerKeyHash));
    sb.append("\n" +  certSerialNumber.toString());
    return sb.toString();
}
 
Example #27
Source File: BlockCipherParamsCore.java    From openjdk-jdk9 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 #28
Source File: PBEParameters.java    From openjdk-jdk9 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 #29
Source File: CertId.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
}
 
Example #30
Source File: RC2Parameters.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected String engineToString() {
    String LINE_SEP = System.getProperty("line.separator");
    HexDumpEncoder encoder = new HexDumpEncoder();
    StringBuilder sb
        = new StringBuilder(LINE_SEP + "    iv:" + LINE_SEP + "["
            + encoder.encodeBuffer(iv) + "]");

    if (version != 0) {
        sb.append(LINE_SEP + "version:" + LINE_SEP
            + version + LINE_SEP);
    }
    return sb.toString();
}