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.ebay.pulsar.analytics.metricstore.druid.metric.MetricTest.java

public void testLexicographicMetric() {
    String previousStop = "LexicoGraphicMetricTest";

    LexicographicMetric lexicoGraphMetric = new LexicographicMetric(previousStop);

    String previousStopGot = lexicoGraphMetric.getPreviousStop();
    assertEquals("FieldName must be 'FieldName'", previousStop, previousStopGot);

    byte[] cacheKey = lexicoGraphMetric.cacheKey();

    String hashCacheKeyExpected = "d782ebbc81c4e652f2928f2ddc4e437fdffdfd6d";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);

    LexicographicMetric lexicoGraphMetric1 = new LexicographicMetric(null);

    byte[] cacheKey1 = lexicoGraphMetric1.cacheKey();

    String hashCacheKeyExpected1 = "bf8b4530d8d246dd74ac53a13471bba17941dff7";
    String hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1);

    MetricType type = lexicoGraphMetric.getType();
    assertEquals("Type NOT Equals", MetricType.lexicographic, type);
}

From source file:com.ebay.pulsar.analytics.metricstore.druid.having.HavingTest.java

public void testNotHaving() {
    String dim = "Aggregate";
    String val = "Value";
    EqualToHaving having = new EqualToHaving(dim, val);

    NotHaving notHaving = new NotHaving(having);

    byte[] cacheKey = notHaving.cacheKey();

    String hashCacheKeyExpected = "46c10224ebf198dab14da05b60b14a82589f39ad";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);

    EqualToHaving having1 = (EqualToHaving) notHaving.getHavingSpec();
    having1 = new EqualToHaving(dim, null);
    NotHaving notHaving1 = new NotHaving(having1);

    byte[] cacheKey1 = notHaving1.cacheKey();

    String hashCacheKeyExpected1 = "74e6b042668b6ee8b0d3d7f49c9ba166a0be2b75";
    String hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1);

    HavingType type = notHaving.getType();
    assertEquals("HavingType NOT Equals", HavingType.not, type);

    String dim2 = "Aggregate2";
    String val2 = "Value2";
    EqualToHaving having2 = new EqualToHaving(dim2, val2);

    NotHaving Having2 = new NotHaving(having2);
    NotHaving Having1 = new NotHaving(null);
    assertTrue(!Having2.equals(Having1));
    assertTrue(!Having1.equals(Having2));
    Having1 = new NotHaving(having2);
    assertTrue(Having2.equals(Having1));
    assertTrue(Having2.hashCode() == Having1.hashCode());
    assertTrue(Having2.equals(Having2));
    assertTrue(!Having2.equals(new NotHaving(having2) {

    }));/*from  www  .  j a va 2  s .c  om*/

}

From source file:com.gson.oauth.Pay.java

/**
 * ??/*w w w . j a v  a  2  s. c o  m*/
 * @param timestamp
 * @param noncestr
 * @param openid
 * @param issubscribe
 * @param appsignature
 * @return
 * @throws UnsupportedEncodingException 
 */
public static boolean verifySign(long timestamp, String noncestr, String openid, int issubscribe,
        String appsignature) throws UnsupportedEncodingException {
    Map<String, String> paras = new HashMap<String, String>();
    paras.put("appid", ConfKit.get("AppId"));
    paras.put("appkey", ConfKit.get("paySignKey"));
    paras.put("timestamp", String.valueOf(timestamp));
    paras.put("noncestr", noncestr);
    paras.put("openid", openid);
    paras.put("issubscribe", String.valueOf(issubscribe));
    // appid?appkey?productid?timestamp?noncestr?openid?issubscribe
    String string1 = createSign(paras, false);
    String paySign = DigestUtils.shaHex(string1);
    return paySign.equalsIgnoreCase(appsignature);
}

From source file:corner.cache.services.impl.CacheableDefinitionParserImpl.java

/**
 * @see corner.cache.services.CacheableDefinitionParser#parseAsKey(org.apache.tapestry5.ioc.Invocation, java.lang.reflect.Method, corner.cache.services.CacheManager)
 *///  w w w  . java2s  .com
@Override
public String parseAsKey(Invocation invocation, Method method) {
    Cacheable cacheable = method.getAnnotation(Cacheable.class);
    if (cacheable == null) {
        return null;
    }
    Definition define = null;
    //if (define == null) { // ?
    Builder defineBuilder = CacheableDefine.Definition.newBuilder();
    Annotation[][] parametersAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parametersAnnotations.length; i++) {
        Annotation[] pa = parametersAnnotations[i];
        for (Annotation a : pa) {
            if (a instanceof CacheKeyParameter) {
                defineBuilder.addParameterIndex(i);
            }
        }
    }
    define = defineBuilder.build();

    // ?
    List<String> keyParameter = new ArrayList<String>();
    Object pObj;
    Class pType;
    for (int i = 0; i < define.getParameterIndexCount(); i++) {
        int pIndex = define.getParameterIndex(i);
        pObj = invocation.getParameter(pIndex);
        pType = null;
        if (pObj != null) {
            pType = entityService.getEntityClass(pObj);
        }
        if (pType == null) {
            pType = method.getParameterTypes()[pIndex];
        }
        ValueEncoder encoder = valueEncoderSource.getValueEncoder(pType);
        keyParameter.add(encoder.toClient(pObj));
    }
    //key
    String key = null;
    String keyFormat = cacheable.keyFormat();
    logger.debug("key parameter:{}", keyParameter);
    if (!StringUtils.hasText(keyFormat)) {
        key = DigestUtils.shaHex(method.toString() + keyParameter.toString());
    } else {
        key = String.format(keyFormat, keyParameter.toArray(new Object[0]));
    }

    CacheStrategy strategy = this.source.findStrategy(cacheable.strategy());
    CacheNsParameter[] nses = cacheable.namespaces();
    if (strategy == null) {
        throw new RuntimeException("fail to find cache strategy instance!");
    }
    return strategy.appendNamespace(cacheManager, cacheable.clazz(), nses, key, keyParameter.toArray());
}

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

public void testCountAggregator() {
    String aggregatorName = "CountAggrTest";

    CountAggregator countAggr = new CountAggregator(aggregatorName);

    byte[] cacheKey = countAggr.cacheKey();

    String hashCacheKeyExpected = "36f680f51c5c6c258211a80db8498fda80c748f9";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);
    AggregatorType type = countAggr.getType();
    assertEquals("Type NOT Equals", AggregatorType.count, type);

    String aggregatorName2 = "CardAggrTest2";
    CountAggregator agg2 = new CountAggregator(aggregatorName2);
    CountAggregator agg3 = new CountAggregator(aggregatorName2);
    assertTrue(agg2.hashCode() == agg3.hashCode());
    assertTrue(agg2.equals(agg2));/* w w w .j  a v  a 2  s .c om*/
    assertTrue(agg2.equals(agg3));
    assertTrue(!agg2.equals(null));
    agg3 = new CountAggregator(aggregatorName);
    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));

}

From source file:com.autentia.tnt.manager.security.AuthenticationManager.java

/**
 * //from w w w .  ja  v a2  s  .  com
 * @param user
 * @param passwd
 * @throws com.autentia.tnt.util.HashEngineException
 * @return
 */
public boolean checkPassword(User user, String passwd) {
    return DigestUtils.shaHex(passwd).equalsIgnoreCase(user.getPassword());
}

From source file:com.bearstouch.android.core.InstallTracker.java

private boolean verifyInstallID() {

    String digestTemp = DigestUtils.shaHex(mUniqueID + Long.toString(mInstallTimeStamp));
    if (mTimeStampHash.compareTo(digestTemp) != 0) {
        return false;
    } else {//from w  w w  . j  a  va  2s.  c o  m
        return true;
    }
}

From source file:com.autentia.tnt.manager.security.AuthenticationManager.java

/**
 * /*www.ja v  a2 s. c o  m*/
 * @param user
 * @param passwd
 * @throws com.autentia.tnt.util.HashEngineException
 */
public void changePassword(User user, String passwd) {
    user.setPassword(DigestUtils.shaHex(passwd));
}

From source file:com.boozallen.cognition.ingest.storm.bolt.starter.LineRegexReplaceInRegionBolt.java

@Override
protected void execute(Tuple tuple, RecordCollector collector) {
    byte[] bytes = (byte[]) tuple.getValue(0);
    String record = new String(bytes);
    String sha1Checksum = DigestUtils.shaHex(bytes);

    if (StringUtils.isBlank(record)) {
        // skips blank entries
        logger.info("received blank record");
        return;//  ww  w.jav a2  s.co m
    }

    LogRecord logRecord = new LogRecord(sha1Checksum);
    logRecord.addMetadataValue(SHA1_CHECKSUM, sha1Checksum);

    String recordAfterReplace = replaceAll(record);
    populateLogRecord(logRecord, recordAfterReplace);

    collector.emit(logRecord);
}

From source file:edu.isi.karma.kr2rml.template.TemplateTermSetPopulator.java

protected List<PopulatedTemplateTermSet> generatePopulatedTemplates(List<PartiallyPopulatedTermSet> partials,
        StringBuilder output, List<TemplateTerm> terms) {
    List<PopulatedTemplateTermSet> templates = new LinkedList<>();

    for (PartiallyPopulatedTermSet partial : partials) {
        StringBuilder uri = new StringBuilder();
        Map<ColumnTemplateTerm, Node> references = new HashMap<>();
        boolean allTermsSatisifed = true;
        boolean atLeastOneTermSatisified = false;
        for (TemplateTerm term : terms) {
            if (term instanceof ColumnTemplateTerm) {
                Node n = partial.getValue((ColumnTemplateTerm) term);
                if (n == null) {
                    allTermsSatisifed = false;
                    continue;
                }//from www. j av a 2s  .  co  m
                if (n.getValue() == null || n.getValue().asString() == null || n.getValue().isEmptyValue()
                        || n.getValue().asString().trim().isEmpty()) {
                    allTermsSatisifed = false;
                } else {
                    atLeastOneTermSatisified = true;
                }
                references.put((ColumnTemplateTerm) term, n);
                if (useNodeValue) {
                    uri.append(n.getValue().asString());
                } else {
                    uri.append("_");
                    String value = n.getValue().asString();
                    value = DigestUtils.shaHex(value);
                    uri.append(value);
                    uri.append("_" + n.getId());
                }
            } else {
                uri.append(term.getTemplateTermValue());
            }
        }
        if (areTermsSatisified(allTermsSatisifed, atLeastOneTermSatisified)) {
            String value = uri.toString();
            if (URIify) {
                value = formatter.getExpandedAndNormalizedUri(value);
            }
            templates.add(new PopulatedTemplateTermSet(originalTerms, references, value));
        }

    }
    return templates;
}