Example usage for org.apache.commons.codec.digest DigestUtils shaHex

List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils shaHex.

Prototype

@Deprecated
    public static String shaHex(String data) 

Source Link

Usage

From source file:com.shlaunch.weixin.local.web.AbstractController.java

protected boolean checkSignature(String signature, String timestamp, String nonce) {
    String token = TOKEN;//from   ww  w  .  j  av  a  2 s  .  co  m
    String[] str = { token, timestamp, nonce };
    Arrays.sort(str); // ??
    String bigStr = str[0] + str[1] + str[2];
    String sha = DigestUtils.shaHex(bigStr);
    logger.debug("bigStr:" + bigStr + ",sha:" + sha);
    if (signature.equals(sha)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.ideabase.repository.core.service.HashMapStateManagerImpl.java

public String generateRequestStateToken() {
    final StringBuilder builder = new StringBuilder();
    builder.append(mPrefix).append(System.nanoTime()).append(Math.random() * 100).append(mSuffix);
    return DigestUtils.shaHex(builder.toString());
}

From source file:be.fedict.eid.dss.model.bean.AdministratorManagerBean.java

private String getId(X509Certificate certificate) {
    PublicKey publicKey = certificate.getPublicKey();
    String id = DigestUtils.shaHex(publicKey.getEncoded());
    return id;
}

From source file:com.atlassian.jira.web.action.setup.SetupProductBundleHelper.java

public void enableWebSudo() {
    final HttpClient httpClient = prepareClient();
    final PostMethod method = new PostMethod(getWebSudoUrl());

    final String token = DigestUtils
            .shaHex(String.valueOf(System.currentTimeMillis() + String.valueOf(Math.random())));
    sharedVariables.setWebSudoToken(token);

    try {/*  w w  w . ja v  a 2  s  .  co  m*/
        method.setParameter("webSudoToken", token);

        final int status = httpClient.executeMethod(method);
        if (status == 200) {
            saveCookies(httpClient.getState().getCookies());
        } else {
            log.warn("Problem when enabling websudo during product bundle license installation, status code: "
                    + status);
        }
    } catch (final IOException e) {
        log.warn("Problem when enabling websudo during product bundle license installation", e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.payu.sdk.utils.SignUtil.java

/**
 * Generates the signature based on information received.
 *
 * @param algorithm The algorithm used to generate the sign.
 * @param key The message key./*from w ww. j  a  v  a2s. c o  m*/
 * @param message The message to create the signature.
 * @return the signature created.
 */
public static String createSignature(final String algorithm, final String key, final String message) {

    final String str = key + SIGNATURE_SEPARATOR + message;
    String signature = null;

    final String localAlgorithm = StringUtils.isBlank(algorithm) ? DEFAULT_ALGORITHM : algorithm;
    if (Constants.ALGORITHM_MD5.equalsIgnoreCase(localAlgorithm)) {
        signature = DigestUtils.md5Hex(str);
    } else if (Constants.ALGORITHM_SHA.equalsIgnoreCase(localAlgorithm)) {
        signature = DigestUtils.shaHex(str);
    } else if (Constants.ALGORITHM_SHA_256.equalsIgnoreCase(localAlgorithm)) {
        signature = DigestUtils.sha256Hex(str);
    } else {
        throw new IllegalArgumentException("Could not create signature. Invalid algorithm " + localAlgorithm);
    }
    return signature;
}

From source file:com.book.identification.task.BookSearch.java

@Override
public void run() {

    List<Volume> volumes = DAOFactory.getInstance().getVolumeDAO().findAll();

    for (Volume volume : volumes) {
        indexedFiles.add(new File(volume.getPath()));
    }//www.  j  a va  2  s . c om
    Collection<File> entries = FileUtils.listFiles(root, new SuffixFileFilter(new String[] { ".pdf", ".chm" }),
            TrueFileFilter.INSTANCE);
    for (File fileToProcces : entries) {

        String fileSHA1 = null;
        try {
            fileSHA1 = DigestUtils.shaHex(FileUtils.openInputStream(fileToProcces));
        } catch (IOException e1) {
            continue;
        }
        logger.info("Accepted file -> " + fileToProcces.getName() + " Hash -> " + fileSHA1);
        FileType fileType = FileType
                .valueOf(StringUtils.upperCase(FilenameUtils.getExtension(fileToProcces.getName())));
        try {
            fileQueue.put(new BookFile(fileToProcces, fileSHA1, fileType));
        } catch (InterruptedException e) {
            logger.info(e);
        }
    }
    nextWorker.notifyEndProducers();
}

From source file:com.lazerycode.selenium.filedownloader.CheckFileHash.java

/**
 * Performs a expectedFileHash check on a File.
 *
 * @return//from   ww w  .j  a  v a 2s  . c om
 * @throws IOException
 */
public boolean hasAValidHash() throws IOException {
    if (this.fileToCheck == null)
        throw new FileNotFoundException("File to check has not been set!");
    if (this.expectedFileHash == null || this.typeOfOfHash == null)
        throw new NullPointerException("Hash details have not been set!");

    String actualFileHash = "";
    boolean isHashValid = false;

    switch (this.typeOfOfHash) {
    case MD5:
        actualFileHash = DigestUtils.md5Hex(new FileInputStream(this.fileToCheck));
        if (this.expectedFileHash.equals(actualFileHash))
            isHashValid = true;
        break;
    case SHA1:
        actualFileHash = DigestUtils.shaHex(new FileInputStream(this.fileToCheck));
        if (this.expectedFileHash.equals(actualFileHash))
            isHashValid = true;
        break;
    }

    //  LOG.info("Filename = '" + this.fileToCheck.getName() + "'");
    // LOG.info("Expected Hash = '" + this.expectedFileHash + "'");
    //LOG.info("Actual Hash = '" + actualFileHash + "'");

    return isHashValid;
}

From source file:be.fedict.eid.idp.sp.wsfed.WSFedAuthenticationResponseServiceBean.java

@Override
public void validateServiceCertificate(SamlAuthenticationPolicy authenticationPolicy,
        List<X509Certificate> certificateChain) throws SecurityException {

    LOG.debug("validate saml response policy=" + authenticationPolicy.getUri() + " cert.chain.size="
            + certificateChain.size());/*from  w  ww.j  a v a  2 s .c  o m*/

    String idpIdentity = ConfigServlet.getIdpIdentity();

    if (null != idpIdentity && !idpIdentity.trim().isEmpty()) {
        LOG.debug("validate IdP Identity with " + idpIdentity);

        String fingerprint;
        try {
            fingerprint = DigestUtils.shaHex(certificateChain.get(0).getEncoded());
        } catch (CertificateEncodingException e) {
            throw new SecurityException(e);
        }

        if (!fingerprint.equals(idpIdentity)) {
            throw new SecurityException(
                    "IdP Identity " + "thumbprint mismatch: got: " + fingerprint + " expected: " + idpIdentity);
        }
    }
}

From source file:be.fedict.eid.idp.sp.saml2.AuthenticationResponseServiceBean.java

@Override
public void validateServiceCertificate(SamlAuthenticationPolicy authenticationPolicy,
        List<X509Certificate> certificateChain) throws SecurityException {

    LOG.debug("validate saml response policy=" + authenticationPolicy.getUri() + " cert.chain.size="
            + certificateChain.size());// ww w .  j  a  v a  2s .co m

    String idpIdentity = ConfigServlet.getIdpIdentity();

    if (null != idpIdentity && !idpIdentity.trim().isEmpty()) {
        LOG.debug("validate IdP Identity with " + idpIdentity);

        String fingerprint;
        try {
            fingerprint = DigestUtils.shaHex(certificateChain.get(0).getEncoded());
        } catch (CertificateEncodingException e) {
            throw new SecurityException(e);
        }

        if (!fingerprint.equals(idpIdentity)) {
            throw new EJBException(
                    "IdP Identity " + "thumbprint mismatch: got: " + fingerprint + " expected: " + idpIdentity);
        }
    }
}

From source file:com.ebay.pulsar.analytics.metricstore.druid.aggregator.AggregatorTest.java

public void testCardinalityAggregator() {
    String aggregatorName = "CardAggrTest";
    List<String> fieldNames = new ArrayList<String>();
    String field1 = "Field1";
    String field2 = "Field2";
    fieldNames.add(field1);/*from  w ww .ja  va2s .c  o  m*/
    fieldNames.add(field2);

    CardinalityAggregator cardAggr = new CardinalityAggregator(aggregatorName, fieldNames);

    cardAggr.setByRow(true);
    boolean byRow = cardAggr.getByRow();
    assertTrue("Property byRow must be TRUE", byRow);
    List<String> fieldNamesGot = cardAggr.getFieldNames();
    assertEquals("1st Field must be 'Field1'", field1, fieldNamesGot.get(0));
    assertEquals("2nd Field must be 'Field2'", field2, fieldNamesGot.get(1));

    byte[] cacheKey = cardAggr.cacheKey();

    String hashCacheKeyExpected = "ecdec9686d4e3f4e137ae430691c5becc2a21192";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);
    AggregatorType type = cardAggr.getType();
    assertEquals("Type NOT Equals", AggregatorType.cardinality, type);

    String aggregatorName2 = "CardAggrTest2";
    List<String> fieldNames2 = new ArrayList<String>();
    String field21 = "Field21";
    String field22 = "Field22";
    fieldNames2.add(field21);
    fieldNames2.add(field22);

    CardinalityAggregator agg2 = new CardinalityAggregator(aggregatorName2, fieldNames2);
    CardinalityAggregator agg3 = new CardinalityAggregator(aggregatorName2, fieldNames2);
    assertTrue(agg2.hashCode() == agg3.hashCode());
    assertTrue(agg2.equals(agg3));
    assertTrue(agg2.equals(agg2));
    agg3.setByRow(true);
    assertTrue(!agg2.equals(agg3));
    assertTrue(!agg3.equals(agg2));
    agg3.setByRow(false);
    assertTrue(agg2.equals(agg2));
    assertTrue(!agg2.equals(cardAggr));
    assertTrue(!agg2.equals(null));
    agg3 = new CardinalityAggregator(aggregatorName2, null);
    assertTrue(!agg2.equals(agg3));
    assertTrue(!agg3.equals(agg2));
    assertTrue(!agg2.equals(new Serializable() {
        private static final long serialVersionUID = 1L;
    }));
    assertTrue(!new Serializable() {
        private static final long serialVersionUID = 1L;
    }.equals(agg2));

}