List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.zimbra.cs.account.TokenUtil.java
public static String getHmac(String data, byte[] key) { try {/* ww w. ja v a2 s. com*/ ByteKey bk = new ByteKey(key); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(bk); return new String(Hex.encodeHex(mac.doFinal(data.getBytes()))); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("fatal error", e); } catch (InvalidKeyException e) { throw new RuntimeException("fatal error", e); } }
From source file:cz.zeno.miner.Utils.java
public static String byteArrayToHexString(byte[] data) { return String.valueOf(Hex.encodeHex(data)); // String ret = ""; // for(byte bb : data) // {/*from w w w. j ava 2s . c o m*/ // ret += String.format("%02X", bb); // } // return ret; }
From source file:fr.free.nrw.commons.Utils.java
/** * Creates an URL for thumbnail/* w w w . ja v a 2s . co m*/ * * @param filename Thumbnail file name * @return URL of thumbnail */ public static String makeThumbBaseUrl(@NonNull String filename) { String name = new PageTitle(filename).getPrefixedText(); String sha = new String(Hex.encodeHex(DigestUtils.md5(name))); return String.format("%s/%s/%s/%s", BuildConfig.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name)); }
From source file:be.fedict.eid.applet.service.impl.tlv.ChipNumberDataConvertor.java
public String convert(byte[] value) throws DataConvertorException { String chipNumber = new String(Hex.encodeHex(value)).toUpperCase(); return chipNumber; }
From source file:be.fedict.commons.eid.consumer.tlv.ChipNumberDataConvertor.java
@Override public String convert(final byte[] value) throws DataConvertorException { return new String(Hex.encodeHex(value)).toUpperCase(); }
From source file:com.wootric.androidsdk.utils.SHAUtil.java
public static String buildUniqueLink(String accountToken, String endUserEmail, long date, String randomString) { String unixTimestamp = String.valueOf(date); String randomText = randomString; String text = accountToken + endUserEmail + unixTimestamp + randomText; MessageDigest mDigest = null; String uniqueLink = null;/* ww w . j a v a2s.c om*/ try { mDigest = MessageDigest.getInstance("SHA-256"); byte[] result = mDigest.digest(text.getBytes()); uniqueLink = new String(Hex.encodeHex(result)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return uniqueLink; }
From source file:com.magic.util.HashCrypt.java
/** * ?hashType//from ww w .jav a 2 s.c o m * @param str * @param hashType * @return */ public static String getDigestHash(String str, String hashType) { if (str == null) return null; try { MessageDigest messagedigest = MessageDigest.getInstance(hashType); byte[] strBytes = str.getBytes(); messagedigest.update(strBytes); byte[] digestBytes = messagedigest.digest(); char[] digestChars = Hex.encodeHex(digestBytes); return "{" + hashType + "}" + new String(digestChars, 0, digestChars.length); } catch (Exception e) { throw new GeneralRuntimeException("Error while computing hash of type " + hashType, e); } }
From source file:io.sidecar.security.SecurityUtils.java
/** * Generates a String representation of an MD5 Checksum from a given String input. * * @param input - A non-null String.//from w w w . j av a 2 s.c om * @return an MD5 checksum as a Hex encoded String. */ public static String md5(String input) { checkNotNull(input); try { //Create MessageDigest object for MD5 MessageDigest digest = MessageDigest.getInstance(MD5_ALGORITHM); //Update input string in message digest digest.update(input.getBytes(), 0, input.length()); //Converts message digest value in base 16 (hex) return String.copyValueOf(Hex.encodeHex(digest.digest())); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } }
From source file:com.mac.hazewinkel.plist.datamodel.PListData.java
@Override public String getAsString() { char[] chars = Hex.encodeHex(value); return new String(chars); }
From source file:com.liferay.portal.util.CookieKeys.java
public static void addCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie, boolean secure) { if (!PropsValues.SESSION_ENABLE_PERSISTENT_COOKIES || PropsValues.TCK_URL) { return;// w w w . j av a 2s .c om } // LEP-5175 String name = cookie.getName(); String originalValue = cookie.getValue(); String encodedValue = originalValue; if (isEncodedCookie(name)) { encodedValue = new String(Hex.encodeHex(originalValue.getBytes())); if (_log.isDebugEnabled()) { _log.debug("Add encoded cookie " + name); _log.debug("Original value " + originalValue); _log.debug("Hex encoded value " + encodedValue); } } cookie.setSecure(secure); cookie.setValue(encodedValue); cookie.setVersion(VERSION); // Setting a cookie will cause the TCK to lose its ability to track // sessions response.addCookie(cookie); }