List of usage examples for org.apache.commons.codec.digest DigestUtils sha
@Deprecated public static byte[] sha(String data)
From source file:com.aipo.container.gadgets.AipoHashLockedDomainService.java
private String getLockedDomain(Gadget gadget, String container) { String suffix = getLockedDomainSuffix(); if (suffix == null) { return null; }/* w w w. ja v a 2s. co m*/ byte[] sha1 = DigestUtils.sha(gadget.getSpec().getUrl().toString()); String hash = new String(Base32.encodeBase32(sha1)); return hash + suffix; }
From source file:com.telefonica.euro_iaas.sdc.util.MixlibAuthenticationDigesterImpl.java
private String getHash(String body) { String b64 = Base64.encodeBase64String(DigestUtils.sha(body.getBytes())); return b64; }
From source file:es.javocsoft.android.lib.toucan.client.request.AppDevTagsOperationRequest.java
/** * Creates a SHA-1 hash from a string.// ww w. j a v a2 s. co m * * @param data * @return */ private String createSHA1Hash(String data) { return new String(Hex.encodeHex(DigestUtils.sha(data))); }
From source file:com.aimluck.eip.services.social.gadgets.ALGadgetContext.java
public String getServerBase() { HttpServletRequest request = ((JetspeedRunData) runData).getRequest(); StringBuilder builder = new StringBuilder(); String scheme = request.getScheme(); String serverName = request.getServerName(); int serverPort = request.getServerPort(); builder.append(scheme).append("://"); if (isLockedDomainRequired()) { byte[] sha1 = DigestUtils.sha(appUrl); String hash = new String(Base32.encodeBase32(sha1)); builder.append(hash).append(getLockedDomainSuffix()); } else {// w w w .ja va 2s .c o m builder.append(serverName); if (serverPort != 80 || serverPort != 443) { builder.append(":").append(serverPort); } } String containerPath = JetspeedResources.getString("aipo.container.path"); return builder.append(containerPath == null ? "" : containerPath).append("/gadgets/").toString(); }
From source file:com.nesscomputing.httpclient.testing.TestingHttpClientBuilderTest.java
License:asdf
@Test public void testBinaryData() throws Exception { byte[] data = DigestUtils.sha("There's no dark side of the moon, really. Matter of fact it's all dark."); TestingHttpClientBuilder builder = new TestingHttpClientBuilder(); builder.on(GET).of("/").respondWith(Response.ok(data)); HttpClient httpClient = builder.build(); HttpClientResponse response = httpClient.get("/", handler).perform(); assertEquals(MediaType.APPLICATION_OCTET_STREAM, response.getContentType()); assertArrayEquals(data, IOUtils.toByteArray(response.getResponseBodyAsStream())); }
From source file:com.google.wave.splash.auth.oauth.OAuthRequestFactory.java
/** * Creates a URL that contains the necessary OAuth query parameters for the * given JSON string.//from w w w .ja v a 2s .c om */ private static String createOAuthUrlString(String jsonBody, String rpcServerUrl, String consumerKey, String consumerSecret) throws IOException, URISyntaxException, OAuthException { OAuthMessage message = new OAuthMessage("POST", rpcServerUrl, Collections.<Map.Entry<String, String>>emptyList()); // Compute the hash of the body. byte[] rawBody = jsonBody.getBytes(HttpMessage.DEFAULT_CHARSET); byte[] hash = DigestUtils.sha(rawBody); byte[] encodedHash = Base64.encodeBase64(hash); message.addParameter("oauth_body_hash", new String(encodedHash, HttpMessage.DEFAULT_CHARSET)); // Add other parameters. OAuthConsumer consumer = new OAuthConsumer(null, "google.com" + ":" + consumerKey, consumerSecret, null); consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1); OAuthAccessor accessor = new OAuthAccessor(consumer); message.addRequiredParameters(accessor); // Construct the resulting URL. StringBuilder sb = new StringBuilder(rpcServerUrl); char connector = '?'; for (Map.Entry<String, String> p : message.getParameters()) { if (!p.getValue().equals(jsonBody)) { sb.append(connector); sb.append(URLEncoder.encode(p.getKey(), HttpMessage.DEFAULT_CHARSET)); sb.append('='); sb.append(URLEncoder.encode(p.getValue(), HttpMessage.DEFAULT_CHARSET)); connector = '&'; } } return sb.toString(); }
From source file:monasca.persister.pipeline.event.MetricHandler.java
private int processEnvelope(MetricEnvelope metricEnvelope) { int metricCount = 0; Metric metric = metricEnvelope.metric; Map<String, Object> meta = metricEnvelope.meta; logger.debug("ordinal: {}", ordinal); logger.debug("metric: {}", metric); logger.debug("meta: {}", meta); String tenantId = ""; if (meta.containsKey(TENANT_ID)) { tenantId = (String) meta.get(TENANT_ID); } else {//from w w w. java 2 s. co m logger.warn( "Failed to find tenantId in message envelope meta data. Metric message may be malformed. Setting tenantId to empty string."); logger.warn("metric: {}", metric.toString()); logger.warn("meta: {}", meta.toString()); } String region = ""; if (meta.containsKey(REGION)) { region = (String) meta.get(REGION); } else { logger.warn( "Failed to find region in message envelope meta data. Metric message may be malformed. Setting region to empty string."); logger.warn("metric: {}", metric.toString()); logger.warn("meta: {}", meta.toString()); } // Add the definition to the batch. StringBuilder definitionIdStringToHash = new StringBuilder(trunc(metric.getName(), MAX_COLUMN_LENGTH)); definitionIdStringToHash.append(trunc(tenantId, MAX_COLUMN_LENGTH)); definitionIdStringToHash.append(trunc(region, MAX_COLUMN_LENGTH)); byte[] definitionIdSha1Hash = DigestUtils.sha(definitionIdStringToHash.toString()); Sha1HashId definitionSha1HashId = new Sha1HashId((definitionIdSha1Hash)); verticaMetricRepository.addDefinitionToBatch(definitionSha1HashId, trunc(metric.getName(), MAX_COLUMN_LENGTH), trunc(tenantId, MAX_COLUMN_LENGTH), trunc(region, MAX_COLUMN_LENGTH)); definitionCounter.inc(); // Calculate dimensions sha1 hash id. StringBuilder dimensionIdStringToHash = new StringBuilder(); Map<String, String> preppedDimMap = prepDimensions(metric.getDimensions()); for (Map.Entry<String, String> entry : preppedDimMap.entrySet()) { dimensionIdStringToHash.append(entry.getKey()); dimensionIdStringToHash.append(entry.getValue()); } byte[] dimensionIdSha1Hash = DigestUtils.sha(dimensionIdStringToHash.toString()); Sha1HashId dimensionsSha1HashId = new Sha1HashId(dimensionIdSha1Hash); // Add the dimension name/values to the batch. for (Map.Entry<String, String> entry : preppedDimMap.entrySet()) { verticaMetricRepository.addDimensionToBatch(dimensionsSha1HashId, entry.getKey(), entry.getValue()); dimensionCounter.inc(); } // Add the definition dimensions to the batch. StringBuilder definitionDimensionsIdStringToHash = new StringBuilder(definitionSha1HashId.toHexString()); definitionDimensionsIdStringToHash.append(dimensionsSha1HashId.toHexString()); byte[] definitionDimensionsIdSha1Hash = DigestUtils.sha(definitionDimensionsIdStringToHash.toString()); Sha1HashId definitionDimensionsSha1HashId = new Sha1HashId(definitionDimensionsIdSha1Hash); verticaMetricRepository.addDefinitionDimensionToBatch(definitionDimensionsSha1HashId, definitionSha1HashId, dimensionsSha1HashId); definitionDimensionsCounter.inc(); // Add the measurements to the batch. if (metric.getTimeValues() != null) { for (double[] timeValuePairs : metric.getTimeValues()) { String timeStamp = simpleDateFormat.format(new Date((long) (timeValuePairs[0] * 1000))); double value = timeValuePairs[1]; verticaMetricRepository.addMetricToBatch(definitionDimensionsSha1HashId, timeStamp, value); metricCounter.inc(); metricCount++; } } else { String timeStamp = simpleDateFormat.format(new Date(metric.getTimestamp() * 1000)); String value = metric.getValue(); verticaMetricRepository.addMetricToBatch(definitionDimensionsSha1HashId, timeStamp, value); metricCounter.inc(); metricCount++; } return metricCount; }
From source file:gobblin.util.guid.Guid.java
@SuppressWarnings("deprecation") private static byte[] computeGuid(byte[] bytes) { return DigestUtils.sha(bytes); }
From source file:mx.bigdata.cfdi.CFDv3.java
byte[] getDigest() throws Exception { byte[] bytes = getOriginalBytes(); return DigestUtils.sha(bytes); }
From source file:monasca.persister.repository.cassandra.CassandraMetricRepo.java
@Override public void addToBatch(MetricEnvelope metricEnvelope, String id) { Metric metric = metricEnvelope.metric; Map<String, Object> metaMap = metricEnvelope.meta; String tenantId = getMeta(TENANT_ID, metric, metaMap, id); String region = getMeta(REGION, metric, metaMap, id); String metricName = metric.getName(); TreeMap<String, String> dimensions = metric.getDimensions() == null ? new TreeMap<String, String>() : new TreeMap<>(metric.getDimensions()); StringBuilder sb = new StringBuilder(region).append(tenantId).append(metricName); Iterator<String> it = dimensions.keySet().iterator(); while (it.hasNext()) { String k = it.next();/*ww w . ja v a 2 s . c om*/ sb.append(k).append(dimensions.get(k)); } byte[] defIdSha = DigestUtils.sha(sb.toString()); Sha1HashId defIdShaHash = new Sha1HashId(defIdSha); if (cluster.getMetricIdCache().getIfPresent(defIdShaHash.toHexString()) == null) { addDefinitionToBatch(defIdShaHash, metricName, dimensions, tenantId, region, id, metric.getTimestamp()); batches.addMeasurementQuery(buildMeasurementInsertQuery(defIdShaHash, metric.getTimestamp(), metric.getValue(), metric.getValueMeta(), region, tenantId, metricName, dimensions, id)); } else { metricCacheHitMeter.mark(); batches.addMetricQuery(cluster.getMetricUpdateStmt().bind(retention, new Timestamp(metric.getTimestamp()), region, tenantId, metricName, getDimensionList(dimensions), new ArrayList<>(dimensions.keySet()))); batches.addMeasurementQuery(buildMeasurementUpdateQuery(defIdShaHash, metric.getTimestamp(), metric.getValue(), metric.getValueMeta(), id)); } metricCount++; }