Example usage for org.apache.commons.codec.binary Hex encodeHexString

List of usage examples for org.apache.commons.codec.binary Hex encodeHexString

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Hex encodeHexString.

Prototype

public static String encodeHexString(byte[] data) 

Source Link

Document

Converts an array of bytes into a String representing the hexadecimal values of each byte in order.

Usage

From source file:eu.europa.esig.dss.cades.signature.CadesLevelBaselineLTATimestampExtractor.java

/**
 * The field certificatesHashIndex is a sequence of octet strings. Each one contains the hash value of one
 * instance of CertificateChoices within certificates field of the root SignedData. A hash value for
 * every instance of CertificateChoices, as present at the time when the corresponding archive time-stamp is
 * requested, shall be included in certificatesHashIndex. No other hash value shall be included in this field.
 *
 * @return//from  ww  w .  jav a2  s . c o m
 * @throws eu.europa.esig.dss.DSSException
 */
private ASN1Sequence getCertificatesHashIndex() throws DSSException {

    final ASN1EncodableVector certificatesHashIndexVector = new ASN1EncodableVector();

    final List<CertificateToken> certificateTokens = cadesSignature.getCertificates();
    for (final CertificateToken certificateToken : certificateTokens) {
        final byte[] encodedCertificate = certificateToken.getEncoded();
        final byte[] digest = DSSUtils.digest(hashIndexDigestAlgorithm, encodedCertificate);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Adding to CertificatesHashIndex DSS-Identifier: {} with hash {}",
                    certificateToken.getDSSId(), Hex.encodeHexString(digest));
        }
        final DEROctetString derOctetStringDigest = new DEROctetString(digest);
        certificatesHashIndexVector.add(derOctetStringDigest);
    }
    return new DERSequence(certificatesHashIndexVector);
}

From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java

/**
 * Calculates the MD5 digest and returns the value as a 32 character hex string.
 *
 * @param data/*from   w w  w.  ja va2s  .  c  o m*/
 *            Data to digest
 * @return MD5 digest as a hex string
 */
public static String md5Hex(final byte[] data) {
    return Hex.encodeHexString(md5(data));
}

From source file:com.continusec.client.VerifiableMap.java

/**
 * Set the value for a given key in the map. Calling this has the effect of adding a mutation to the
 * mutation log for the map, which then reflects in the root hash for the map. This occurs asynchronously.
 * @param key the key to set./*  w ww  .j  a  va  2 s . co  m*/
 * @param e the entry to set to key to. Typically one of {@link RawDataEntry}, {@link JsonEntry} or {@link RedactableJsonEntry}.
 * @return add entry response, which includes the Merkle Tree Leaf hash of the mutation log entry added.
 * @throws ContinusecException upon error
 */
public AddEntryResponse set(byte[] key, UploadableEntry e) throws ContinusecException {
    try {
        JsonObject j = new JsonParser().parse(new String(
                this.client.makeRequest("PUT", this.path + "/key/h/" + Hex.encodeHexString(key) + e.getFormat(),
                        e.getDataForUpload(), null).data,
                "UTF-8")).getAsJsonObject();
        return new AddEntryResponse(Base64.decodeBase64(j.get("leaf_hash").getAsString()));
    } catch (UnsupportedEncodingException e1) {
        throw new ContinusecException(e1);
    }
}

From source file:eu.europa.esig.dss.pdf.pdfbox.PdfBoxSignatureService.java

private PDSignature createSignatureDictionary(final PAdESSignatureParameters parameters) {

    final PDSignature signature = new PDSignature();
    signature.setType(getType());/*from  w  ww .ja va  2s  . co m*/
    //      signature.setName(String.format("SD-DSS Signature %s", parameters.getDeterministicId()));
    Date date = parameters.bLevel().getSigningDate();
    String encodedDate = " " + Hex
            .encodeHexString(DSSUtils.digest(DigestAlgorithm.SHA1, Long.toString(date.getTime()).getBytes()));
    CertificateToken token = parameters.getSigningCertificate();
    if (token == null) {
        signature.setName("Unknown signer" + encodedDate);
    } else {
        if (parameters.getSigningCertificate().getSubjectShortName() != null) {
            String shortName = parameters.getSigningCertificate().getSubjectShortName() + encodedDate;
            signature.setName(shortName);
        } else {
            signature.setName("Unknown signer" + encodedDate);
        }
    }

    signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE); // default filter
    // sub-filter for basic and PAdES Part 2 signatures
    signature.setSubFilter(getSubFilter());

    if (COSName.SIG.equals(getType())) {
        if (StringUtils.isNotEmpty(parameters.getContactInfo())) {
            signature.setContactInfo(parameters.getContactInfo());
        }

        if (StringUtils.isNotEmpty(parameters.getLocation())) {
            signature.setLocation(parameters.getLocation());
        }

        if (StringUtils.isNotEmpty(parameters.getReason())) {
            signature.setReason(parameters.getReason());
        }
    }

    // the signing date, needed for valid signature
    final Calendar cal = Calendar.getInstance();
    final Date signingDate = parameters.bLevel().getSigningDate();
    cal.setTime(signingDate);
    signature.setSignDate(cal);
    return signature;
}

From source file:com.github.axet.androidlibrary.crypto.RipeMD160.java

public boolean selfTest() {
    if (valid == null) {
        String d = Hex.encodeHexString(new RipeMD160().digest());
        valid = Boolean.valueOf(DIGEST0.equals(d));
    }/*from   www. j  a v a 2  s .c o m*/
    return valid.booleanValue();
}

From source file:eu.europa.ec.markt.dss.validation.pades.PAdESSignature.java

@Override
public String getId() {
    try {/*from   ww w.ja  v  a2s. co m*/

        MessageDigest digest = MessageDigest.getInstance("MD5");
        if (getSigningTime() != null) {
            digest.update(Long.toString(getSigningTime().getTime()).getBytes());
        }
        digest.update(getSigningCertificate().getEncoded());
        return Hex.encodeHexString(digest.digest());
    } catch (Exception e) {

        throw new RuntimeException(e);
    }
}

From source file:libepg.epg.section.body.networkinformationtable.NetworkInformationTableBody.java

/**
 * transport_stream_loop_length????CRC_32
 * ????????????? 12 ???//from  ww w  .ja v a2s  .c om
 * @return ?
 */
public synchronized int getTransport_stream_loop_length() {
    byte[] t = new byte[2];
    System.arraycopy(this.getData(), 5 + this.getDescriptors_loop_length() + 1 + 1, t, 0, t.length);
    int it = ByteConverter.bytesToInt(t);
    it = it & 0x0FFF;
    LOG.trace(Hex.encodeHexString(t) + " -> " + Integer.toHexString(it));
    return it;
}

From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java

/**
 * Calculates the MD5 digest and returns the value as a 32 character hex string.
 *
 * @param data/* w  ww  . j av  a  2 s  . com*/
 *            Data to digest
 * @return MD5 digest as a hex string
 * @throws IOException
 *             On error reading from the stream
 * @since 1.4
 */
public static String md5Hex(final InputStream data) throws IOException {
    return Hex.encodeHexString(md5(data));
}

From source file:com.oculusinfo.factory.ConfigurableFactory.java

/**
 * Return a SHA-256 hexcode representing the state of the configuration
 * @return String representing the hexcode SHA-256 hash of the configuration state
 *///w  w  w.  ja  v  a2  s. c o m
public String generateSHA256() {
    try {
        String propertyString = getFactoryString();
        // generate SHA-256 from the string
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(propertyString.getBytes("UTF-8"));
        byte[] digest = md.digest();
        // convert SHA-256 bytes to hex string
        return Hex.encodeHexString(digest);
    } catch (Exception e) {
        LOGGER.warn("Error registering configuration to SHA", e);
        return "";
    }
}

From source file:libepg.ts.reader.Reader2.java

/**
 * ??????<br>/*w  w  w . j a  v  a  2 s.  c  om*/
 * 1:???????????1??????<br>
 * 2:?????????????<br>
 * 3:??????1??????<br>
 * ???????????<br>
 * 4:1?<br>
 *
 * @return ???
 */
public synchronized List<TsPacket> getPackets() {
    ByteBuffer packetBuffer = ByteBuffer.allocate(TsPacket.TS_PACKET_BYTE_LENGTH.PACKET_LENGTH.getByteLength());
    byte[] byteData = new byte[1];

    //?
    List<TsPacket> packets = new ArrayList<>();

    FileInputStream fis = null;
    PushbackInputStream pis = null;
    try {

        fis = new FileInputStream(this.TSFile);
        pis = new PushbackInputStream(fis);

        boolean tipOfPacket = false;//?

        long count = 0;

        //??????1??????
        while (pis.read(byteData) != EOF) {

            //???????????????
            if ((byteData[0] == TsPacket.TS_SYNC_BYTE) && (tipOfPacket == false)) {
                tipOfPacket = true;
                if (LOG.isTraceEnabled() && NOT_DETERRENT_READ_TRACE_LOG) {
                    LOG.trace(
                            "???????????1????");
                }
                pis.unread(byteData);
            }

            if (tipOfPacket == true) {
                byte[] tsPacketData = new byte[TsPacket.TS_PACKET_BYTE_LENGTH.PACKET_LENGTH.getByteLength()];
                if (pis.read(tsPacketData) != EOF) {
                    if (LOG.isTraceEnabled() && NOT_DETERRENT_READ_TRACE_LOG) {
                        LOG.trace(
                                "??????????????");
                    }
                    packetBuffer.put(tsPacketData);
                } else {
                    break;
                }
            }

            if (packetBuffer.remaining() == 0) {
                byte[] BeforeCutDown = packetBuffer.array();
                byte[] AfterCutDown = new byte[packetBuffer.position()];
                System.arraycopy(BeforeCutDown, 0, AfterCutDown, 0, AfterCutDown.length);

                //??????????
                TsPacket tsp = new TsPacket(AfterCutDown);

                //                        LOG.debug(Hex.encodeHexString(tsp.getData()));
                if (LOG.isTraceEnabled() && NOT_DETERRENT_READ_TRACE_LOG) {
                    LOG.trace(
                            "1???????? ");
                    LOG.trace(tsp.toString());
                }

                if (tsp.getTransport_error_indicator() != 0) {
                    if (LOG.isWarnEnabled()) {
                        LOG.warn(
                                "??1????????????????????");
                        LOG.warn(tsp);
                        LOG.warn(TSFile);
                    }
                    tipOfPacket = false;
                } else {
                    packets.add(tsp);
                    count++;
                }
                packetBuffer.clear();
                tipOfPacket = false;

                if (this.readLimit != null && count >= this.readLimit) {
                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                                "????????????? ?? = "
                                        + this.readLimit);
                    }
                    break;
                }
            }

        }
        if (LOG.isTraceEnabled() && NOT_DETERRENT_READ_TRACE_LOG) {
            LOG.trace("?????????");
            LOG.trace(" = " + Hex.encodeHexString(packetBuffer.array()));
        }

        pis.close();
        fis.close();
        LOG.info("??? = " + count);

    } catch (FileNotFoundException e) {
        LOG.fatal("?????", e);
    } catch (IOException e) {
        LOG.fatal("???", e);
    }
    return Collections.unmodifiableList(packets);
}