/** * Calculate the MD5 digest of the given bytes. * * @param bytes * the bytes to calculate the digest over * @return the digest */ public static byte[] sha1Digest(byte[] bytes) { return digest(SHA1_ALGORITHM_NAME, bytes); }
private static byte[] digest(String algorithm, byte[] bytes) { return getDigest(algorithm).digest(bytes); }
public String generateRequestCacheKey(HttpServletRequest request) { StringBuilder cacheKey = new StringBuilder(UrlUtils.getCurrentUri(request)); return DigestUtils.md5Digest(cacheKey.toString()); }
public static String md5Digest(String string) { Validate.notBlank(string, "The string to get the hash from cannot be blank"); char[] encodedDigest; try { byte[] digest = digest(MD5_ALGORITHM_NAME, string.getBytes("UTF-8")); encodedDigest = encodeHex(digest); } catch (UnsupportedEncodingException e) { throw new DandelionException("Unable to get a MD5 hash of " + string, e); } return new String(encodedDigest); }
public String generateRequestCacheKey(HttpServletRequest request) { StringBuilder cacheKey = new StringBuilder(UrlUtils.getCurrentUri(request)); return DigestUtils.md5Digest(cacheKey.toString()); }
public static String md5Digest(String string) { Validate.notBlank(string, "The string to get the hash from cannot be blank"); char[] encodedDigest; try { byte[] digest = digest(MD5_ALGORITHM_NAME, string.getBytes("UTF-8")); encodedDigest = encodeHex(digest); } catch (UnsupportedEncodingException e) { throw new DandelionException("Unable to get a MD5 hash of " + string, e); } return new String(encodedDigest); }
etagValue.append(DigestUtils.md5Digest(new String(response, configuration.getEncoding()))); etagValue.append("\"");
/** * Calculate the MD5 digest of the given bytes. * * @param bytes * the bytes to calculate the digest over * @return the digest */ public static byte[] md5Digest(byte[] bytes) { return digest(MD5_ALGORITHM_NAME, bytes); }
private static byte[] digest(String algorithm, byte[] bytes) { return getDigest(algorithm).digest(bytes); }
etagValue.append(DigestUtils.md5Digest(new String(response, configuration.getEncoding()))); etagValue.append("\"");
/** * Calculate the MD5 digest of the given bytes. * * @param bytes * the bytes to calculate the digest over * @return the digest */ public static byte[] md5Digest(byte[] bytes) { return digest(MD5_ALGORITHM_NAME, bytes); }
@Override public boolean handle(HandlerContext handlerContext) { // Generate a brand new request key String requestKey = DigestUtils.md5Digest(UUID.randomUUID().toString()); // Create a new instance intended to be stored in session RequestFlashData requestData = new RequestFlashData(handlerContext.getRequest()); // Store request data in cache for later use handlerContext.getContext().getRequestFlashDataCache().put(requestKey, requestData); // Store the generated request key as a request attribute for later use handlerContext.getRequest().setAttribute(WebConstants.DANDELION_REQUEST_KEY, requestKey); return true; } }
/** * Calculate the MD5 digest of the given bytes. * * @param bytes * the bytes to calculate the digest over * @return the digest */ public static byte[] sha1Digest(byte[] bytes) { return digest(SHA1_ALGORITHM_NAME, bytes); }
@Override public boolean handle(HandlerContext handlerContext) { // Generate a brand new request key String requestKey = DigestUtils.md5Digest(UUID.randomUUID().toString()); // Create a new instance intended to be stored in session RequestFlashData requestData = new RequestFlashData(handlerContext.getRequest()); // Store request data in cache for later use handlerContext.getContext().getRequestFlashDataCache().put(requestKey, requestData); // Store the generated request key as a request attribute for later use handlerContext.getRequest().setAttribute(WebConstants.DANDELION_REQUEST_KEY, requestKey); return true; } }
@Override public String getAssetVersion(Asset asset) { LOG.debug("Calculating version hash for the asset: {}", asset.toLog()); StorageEntry storageEntry = getContext().getAssetStorage().get(asset.getStorageKey()); String contents = null; if(storageEntry != null) { contents = storageEntry.getContents(); } String version = null; if (StringUtils.isBlank(contents)) { LOG.warn("Asset {} has an empty contents. Using a random String for the hash", asset.toLog()); version = DigestUtils.md5Digest(UUID.randomUUID().toString()); } else { version = DigestUtils.md5Digest(contents); } return version; } }
@Override public String getAssetVersion(Asset asset) { LOG.debug("Calculating version hash for the asset: {}", asset.toLog()); StorageEntry storageEntry = getContext().getAssetStorage().get(asset.getStorageKey()); String contents = null; if(storageEntry != null) { contents = storageEntry.getContents(); } String version = null; if (StringUtils.isBlank(contents)) { LOG.warn("Asset {} has an empty contents. Using a random String for the hash", asset.toLog()); version = DigestUtils.md5Digest(UUID.randomUUID().toString()); } else { version = DigestUtils.md5Digest(contents); } return version; } }
/** * <p> * Generates a MD5 hash using information of the provided {@link Asset}. * </p> * <p> * The set of information used to generate the hash depends on the location * key. * </p> * <ul> * <li>{@code webapp}, {@code jar}, {@code webjar}, {@code classpath} and * {@code remote}: bundle name + asset name + asset type</li> * <li>{@code api}: bundle name + asset name + asset type + current URI</li> * </ul> * * @param asset * The asset holding information used to generate the hash. * @return a MD5 hash. */ public static String generateStorageKey(Asset asset, HttpServletRequest request) { Validate.notNull(asset.getConfigLocationKey(), "The location key of the provided asset cannot be null"); StringBuilder keyContext = new StringBuilder(); keyContext.append(asset.getBundle()); keyContext.append(asset.getName()); keyContext.append(asset.getType().name()); if (asset.getConfigLocationKey().equalsIgnoreCase(ApiLocator.LOCATION_KEY)) { keyContext.append(UrlUtils.getCurrentUri(request)); } return DigestUtils.md5Digest(keyContext.toString()); }
/** * <p> * Generates a MD5 hash using information of the provided {@link Asset}. * </p> * <p> * The set of information used to generate the hash depends on the location * key. * </p> * <ul> * <li>{@code webapp}, {@code jar}, {@code webjar}, {@code classpath} and * {@code remote}: bundle name + asset name + asset type</li> * <li>{@code api}: bundle name + asset name + asset type + current URI</li> * </ul> * * @param asset * The asset holding information used to generate the hash. * @return a MD5 hash. */ public static String generateStorageKey(Asset asset, HttpServletRequest request) { Validate.notNull(asset.getConfigLocationKey(), "The location key of the provided asset cannot be null"); StringBuilder keyContext = new StringBuilder(); keyContext.append(asset.getBundle()); keyContext.append(asset.getName()); keyContext.append(asset.getType().name()); if (asset.getConfigLocationKey().equalsIgnoreCase(ApiLocator.LOCATION_KEY)) { keyContext.append(UrlUtils.getCurrentUri(request)); } return DigestUtils.md5Digest(keyContext.toString()); }