List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.glaf.core.security.RSAUtils.java
public static void main(String[] args) { RSAPublicKey publicKey = RSAUtils.getDefaultPublicKey(); System.out.println(new String(Hex.encodeHex(publicKey.getModulus().toByteArray()))); System.out.println(new String(Hex.encodeHex(publicKey.getPublicExponent().toByteArray()))); System.out.println(RSAUtils.decryptStringByJs( "2d7754804ecfb3c3e6fb7d12cdf439036f1d8e2ad34c5a6467bd6f1c165bb47f0fa57134b013aba49be5edf5231c2f7b611af5e974b521ea715b1a6bad6cfbf4ba8e0886c5fe1ce903d30ae0c8cd5f422860d67fa4fd3e2a8fc7872c6b052a6c8f480cfde5e147d959f3db5032767c393ff271742f66be7657290a5de218e375")); }
From source file:com.fegor.alfresco.security.crypto.Crypto.java
public String getVectorInit() { return (new String(Hex.encodeHex(vector_init))); }
From source file:com.google.caja.precajole.StaticPrecajoleMap.java
private static String computeHash(String s) { try {//from w w w .j a v a2 s .c om MessageDigest sha1 = MessageDigest.getInstance("SHA1"); byte[] digest = sha1.digest(s.getBytes("UTF-8")); return new String(Hex.encodeHex(digest)); } catch (NoSuchAlgorithmException e) { throw new SomethingWidgyHappenedError(e); } catch (UnsupportedEncodingException e) { throw new SomethingWidgyHappenedError(e); } }
From source file:com.redhat.rhn.common.util.SHA256Crypt.java
/** * SHA256 and Hexify an array of bytes. Take the input array, SHA256 encodes it * and then turns it into Hex./*from w w w. j av a 2 s . c o m*/ * @param secretBytes you want sha256hexed * @return sha256hexed String. */ public static String sha256Hex(byte[] secretBytes) { String retval = null; // add secret MessageDigest md; md = getSHA256MD(); md.update(secretBytes); // generate the digest byte[] digest = md.digest(); // hexify this puppy retval = new String(Hex.encodeHex(digest)); return retval; }
From source file:edu.psu.citeseerx.utility.FileDigest.java
/** * Informs if the SHA-1 file digest is equals to a given digest * @param digest digest a <code>byte[]</code> that represents a file digest * @param filePath Parent abstract pathname * @param fileName Child path name//from www . ja v a 2s .co m * @return true if the SHA-1 file digest is equals to digest */ public static boolean validateSHA1(byte[] digest, String filePath, String fileName) { String fileDigest = new String(Hex.encodeHex(digest)); return validateSHA1(fileDigest, new File(filePath, fileName)); }
From source file:com.jpeterson.util.etag.FileETagTest.java
/** * Test the calculate method using the default characteristics: file last * modified and file size.// www.java 2s . co m */ public void test_calculateDefaultLastModifiedAndSize() { File file; String content = "Hello, world!"; String expected; FileETag etag; try { // create temporary file file = File.createTempFile("temp", "txt"); // make sure that it gets cleaned up file.deleteOnExit(); // put some date in the file FileOutputStream out = new FileOutputStream(file); out.write(content.getBytes()); out.flush(); out.close(); // manipulate the last modified value to a "known" value SimpleDateFormat date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); long lastModified = date.parse("06/21/2007 11:19:36").getTime(); file.setLastModified(lastModified); // determined expected StringBuffer buffer = new StringBuffer(); buffer.append(lastModified); buffer.append(content.length()); MessageDigest messageDigest = MessageDigest.getInstance("MD5"); expected = new String(Hex.encodeHex(messageDigest.digest(buffer.toString().getBytes()))); etag = new FileETag(); String value = etag.calculate(file); assertEquals("Unexpected value", expected, value); } catch (FileNotFoundException e) { e.printStackTrace(); fail("Unexpected exception"); } catch (IOException e) { e.printStackTrace(); fail("Unexpected exception"); } catch (ParseException e) { e.printStackTrace(); fail("Unexpected exception"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); fail("Unexpected exception"); } }
From source file:com.netflix.astyanax.thrift.AbstractThriftMutationBatchImpl.java
/** * Generate a string representation of the mutation with the following * syntax Key1: cf1: Mutation count cf2: Mutation count Key2: cf1: Mutation * count cf2: Mutation count/*from ww w . j ava 2 s. c om*/ */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ThriftMutationBatch["); boolean first = true; for (Entry<ByteBuffer, Map<String, List<Mutation>>> row : mutationMap.entrySet()) { if (!first) sb.append(","); sb.append(Hex.encodeHex(row.getKey().array())).append("("); boolean first2 = true; for (Entry<String, List<Mutation>> cf : row.getValue().entrySet()) { if (!first2) sb.append(","); sb.append(cf.getKey()).append(":").append(cf.getValue().size()); first2 = false; } first = false; sb.append(")"); } sb.append("]"); return sb.toString(); }
From source file:dk.clanie.io.IOUtil.java
/** * Calculates SHA1 for the contents of the supplied InputStream. * /* w w w.j ava2 s . co m*/ * @param is InputStream * @return String with SHA1 calculated from the contents of <code>is</code>. * * @throws RuntimeIOException */ public static String sha1(InputStream is) { byte[] buf = new byte[1024 * 1024 * 5]; int bytesRead = 0; MessageDigest md; try { md = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException nsae) { throw new RuntimeIOException(nsae.getMessage(), nsae); } try { while ((bytesRead = is.read(buf)) > 0) { md.update(buf, 0, bytesRead); } } catch (IOException ioe) { throw new RuntimeIOException(ioe.getMessage(), ioe); } byte[] digest = md.digest(); String hexDigest = new String(Hex.encodeHex(digest)); return hexDigest; }
From source file:com.spidertracks.datanucleus.query.PelopsIndexingTest.java
@Test public void getAll() throws Exception { Cluster cluster = new Cluster("localhost", 9160); Pelops.addPool(POOL, cluster, KEYSPACE); Selector selector = Pelops.createSelector(POOL); Map<Bytes, List<Column>> values = selector.getColumnsFromRows("Parent", Selector.newKeyRange(Bytes.EMPTY, Bytes.EMPTY, 100), Selector.newColumnsPredicateAll(false), ConsistencyLevel.QUORUM);//ww w .j a v a2 s .c o m for (Bytes key : values.keySet()) { System.out.println(String.format("Key: %s", new String(Hex.encodeHex(key.toByteArray())))); for (Column col : values.get(key)) { System.out.println(String.format("\t name: %s value: %s", new String(Hex.encodeHex(col.getName())), new String(Hex.encodeHex(col.getValue())))); } } }
From source file:com.annuletconsulting.homecommand.server.HomeCommand.java
private static String getSignature(String timeStamp) { if (sharedKey != null) try {/*from w w w .j a va 2 s .c o m*/ byte[] data = timeStamp.getBytes(ENCODING_FORMAT); Mac mac = Mac.getInstance(SIGNATURE_METHOD); mac.init(new SecretKeySpec(sharedKey.getBytes(ENCODING_FORMAT), SIGNATURE_METHOD)); char[] signature = Hex.encodeHex(mac.doFinal(data)); return new String(signature); } catch (Exception exception) { exception.printStackTrace(); } return "Error in getSignature()"; }