List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.netflix.explorers.resources.EmbeddedContentResource.java
@GET @Path("/{subResources:.*}") public Response get(@PathParam("subResources") String subResources) throws Exception { LOG.debug(subResources);/*w w w .j a v a 2 s . c o m*/ String ext = StringUtils.substringAfterLast(subResources, "."); String mediaType = EXT_TO_MEDIATYPE.get(ext); byte[] buffer = null; if (mediaType != null) { InputStream is = getClass().getResourceAsStream("/" + subResources); if (is == null) { throw new WebApplicationException(404); } ByteArrayOutputStream os = new ByteArrayOutputStream(); try { IOUtils.copy(is, os); buffer = os.toByteArray(); } catch (IOException e) { LOG.warn(e.getMessage()); } } if (buffer == null) throw new NotFoundException(); else { if (CACHE_ENABLED) { CacheControl cc = new CacheControl(); cc.setMaxAge(MAX_AGE); cc.setNoCache(false); return Response.ok(buffer, mediaType).cacheControl(cc) .expires(new Date(System.currentTimeMillis() + 3600 * 1000)) .tag(new String( Hex.encodeHex(MessageDigest.getInstance("MD5").digest(subResources.getBytes())))) .build(); } else { return Response.ok(buffer, mediaType).build(); } } }
From source file:com.beligum.core.accounts.UserManager.java
private static String hash(String password, String salt) { KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 2048, 160); try {//w ww. j ava2s .c om SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); byte[] hash = f.generateSecret(spec).getEncoded(); return new String(Hex.encodeHex(hash)); } catch (Exception e) { return null; } }
From source file:azkaban.storage.HdfsStorage.java
private Path createTargetPath(final StorageMetadata metadata, final Path projectsPath) { return new Path(projectsPath, String.format("%s-%s.zip", String.valueOf(metadata.getProjectId()), new String(Hex.encodeHex(metadata.getHash())))); }
From source file:com.youTransactor.uCube.Tools.java
public static double fromBCD_double(byte[] buff) { String val = new String(Hex.encodeHex(buff)); return Double.valueOf(val); }
From source file:com.mastercard.mobile_api.payment.cld.Cld.java
/** * Get the default CLD value with a Random Card Art * *//*www. j a va 2 s . co m*/ private static String getDefaultCldWithCardArt(final int cardArtIndex) { final String CLD_HEADER = "1101011201010137130A04"; final String CLD_TRAILER = "160F1A10020003FFFFFF4578706972657316180807010003" + "FFFFFF4D5220412E2043415244484F4C4445520216131004" + "6261636B5F6261636B67726F756E64150" + "20300012C161B0817030004FFFFFF2A2A2A2A202A2A2A2A2" + "02A2A2A2A202A2A2A2A160D3110010003" + "FFFFFF2A2A2F2A2A020D160B3E1E0540030000002A2A2A"; final String card = new String(Hex.encodeHex(("TVK_" + cardArtIndex + ".png").getBytes())); return CLD_HEADER + card + CLD_TRAILER; }
From source file:com.intellij.ide.passwordSafe.impl.providers.masterKey.PasswordDatabase.java
/** * Covert bytes to hex//from w ww . ja v a 2s .c om * * @param bytes bytes to convert * @return hex representation */ @Nullable private static String toHex(byte[] bytes) { return bytes == null ? null : new String(Hex.encodeHex(bytes)); }
From source file:cascading.tap.hadoop.io.FSDigestInputStream.java
@Override public void close() throws IOException { inputStream.close();//www .j av a 2s .co m LOG.info("closing stream, testing digest: [{}]", digestHex == null ? "none" : digestHex); if (digestHex == null) return; String digestHex = new String(Hex.encodeHex(((DigestInputStream) inputStream).getMessageDigest().digest())); if (!digestHex.equals(this.digestHex)) { String message = "given digest: [" + this.digestHex + "], does not match input stream digest: [" + digestHex + "]"; LOG.error(message); throw new IOException(message); } }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReaderSpi.java
@Override public boolean canDecodeInput(Object source) throws IOException { if (!(source instanceof BufferedInputStream)) { return false; }/* w w w . ja v a 2 s . c om*/ if (source == null) { throw new IllegalArgumentException("stream == null!"); } BufferedInputStream stream = (BufferedInputStream) source; dbgLog.fine("applying the dta test\n"); byte[] b = new byte[DTA_HEADER_SIZE]; if (stream.markSupported()) { stream.mark(0); } int nbytes = stream.read(b, 0, DTA_HEADER_SIZE); if (nbytes == 0) { throw new IOException(); } if (stream.markSupported()) { stream.reset(); } dbgLog.info("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(b)) + "<-"); if (b[2] != 1) { dbgLog.fine("3rd byte is not 1: given file is not stata-dta type"); return false; } else if ((b[1] != 1) && (b[1] != 2)) { dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type"); return false; } else if (!DTAFileReaderSpi.stataReleaseNumber.containsKey(b[0])) { dbgLog.fine("1st byte (" + b[0] + ") is not within the ingestable range [rel. 3-10]:" + "this file is NOT stata-dta type"); return false; } else { dbgLog.fine("this file is stata-dta type: " + DTAFileReaderSpi.stataReleaseNumber.get(b[0]) + "(No in byte=" + b[0] + ")"); return true; } }
From source file:com.amazonaws.cognito.sync.devauth.client.AmazonCognitoSampleDeveloperAuthenticationClient.java
/** * Creates a 128 bit random string..//from w w w. j a v a2s . c om */ public static String generateRandomString() { SecureRandom random = new SecureRandom(); byte[] randomBytes = random.generateSeed(16); String randomString = new String(Hex.encodeHex(randomBytes)); return randomString; }
From source file:com.mastercard.walletservices.mdes.DeviceInfo.java
/** * Return ByteArray of device finger print. * * @return The Device Finger Pring as String *//*w w w.j a v a 2s . co m*/ public String getDeviceFingerprint() { byte[] dataBytes = (this.deviceName + this.deviceType + this.imei + this.msisdn + this.nfcCapable + this.osName).getBytes(); ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[dataBytes.length]); byteBuffer.put(dataBytes); // Create MessageDigest using SHA-256 algorithm Added required MessageDigest messageDigest; try { messageDigest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } // Hash the result byte[] hash = messageDigest.digest(byteBuffer.array()); // Return Hex return new String(Hex.encodeHex(hash)); }