use of com.google.common.hash.Hasher in project java-chassis by ServiceComb.
the class EdgeSignatureRequestFilter method afterReceiveRequest.
@Override
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
EncryptContext encryptContext = (EncryptContext) invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
if (encryptContext == null) {
return null;
}
Hcr hcr = encryptContext.getHcr();
// signature for query and form
List<String> names = Collections.list(requestEx.getParameterNames());
names.sort(Comparator.naturalOrder());
Hasher hasher = Hashing.sha256().newHasher();
hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8);
for (String name : names) {
hasher.putString(name, StandardCharsets.UTF_8);
hasher.putString(requestEx.getParameter(name), StandardCharsets.UTF_8);
}
LOGGER.info("afterReceiveRequest signature: {}", hasher.hash().toString());
return null;
}
use of com.google.common.hash.Hasher in project java-chassis by ServiceComb.
the class SignatureUtils method genSignature.
public static String genSignature(HttpServletRequestEx requestEx) {
Hasher hasher = Hashing.sha256().newHasher();
hasher.putString(requestEx.getRequestURI(), StandardCharsets.UTF_8);
for (String paramName : paramNames) {
String paramValue = requestEx.getHeader(paramName);
if (paramValue != null) {
hasher.putString(paramName, StandardCharsets.UTF_8);
hasher.putString(paramValue, StandardCharsets.UTF_8);
System.out.printf("%s %s\n", paramName, paramValue);
}
}
if (!StringUtils.startsWithIgnoreCase(requestEx.getContentType(), MediaType.APPLICATION_FORM_URLENCODED)) {
byte[] bytes = requestEx.getBodyBytes();
if (bytes != null) {
hasher.putBytes(bytes, 0, requestEx.getBodyBytesLength());
}
}
return hasher.hash().toString();
}
use of com.google.common.hash.Hasher in project gerrit by GerritCodeReview.
the class RevisionResource method getETag.
@Override
public String getETag() {
try (TraceTimer ignored = TraceContext.newTimer("Compute revision ETag", Metadata.builder().changeId(change.getId().get()).patchSetId(ps.number()).projectName(change.getProject().get()).build())) {
Hasher h = Hashing.murmur3_128().newHasher();
prepareETag(h, getUser());
return h.hash().toString();
}
}
use of com.google.common.hash.Hasher in project nzbhydra2 by theotherp.
the class HashPasswordProtector method encryptNow.
private String encryptNow(String plaintext) {
logger.debug("Encrypt:{}", plaintext);
byte[] bytes = plaintext.getBytes(Charsets.UTF_8);
for (int i = 0; i < hashTime - 1; i++) {
Hasher hasher = chooseHasher(algorithm);
bytes = hasher.putBytes(bytes).hash().asBytes();
}
Hasher hasher = chooseHasher(algorithm);
return hasher.putBytes(bytes).hash().toString();
}
use of com.google.common.hash.Hasher in project druid by druid-io.
the class SegmentUtils method hashIds.
/**
* Hash the IDs of the given segments based on SHA-256 algorithm.
*/
public static String hashIds(List<DataSegment> segments) {
Collections.sort(segments);
final Hasher hasher = HASH_FUNCTION.newHasher();
segments.forEach(segment -> hasher.putString(segment.getId().toString(), StandardCharsets.UTF_8));
return StringUtils.fromUtf8(hasher.hash().asBytes());
}
Aggregations