List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.moz.fiji.schema.util.TestJsonEntityIdParser.java
@Test public void testShouldWorkWithRKFHashPrefixedLayout() throws Exception { final TableLayoutDesc desc = FijiTableLayouts.getLayout(FijiTableLayouts.HASH_PREFIXED_RKF); final FijiTableLayout layout = FijiTableLayout.newLayout(desc); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); // Byte array representations of row keys should work. // Prepend appropriate hashed prefix to UNUSUAL_STRING_EID. final byte[] rowKey = Bytes.toBytes(UNUSUAL_STRING_EID); final byte[] hash = Hasher.hash(Bytes.toBytes(UNUSUAL_STRING_EID)); final byte[] hbaseRowKey = new byte[rowKey.length + 2]; System.arraycopy(hash, 0, hbaseRowKey, 0, 2); System.arraycopy(rowKey, 0, hbaseRowKey, 2, rowKey.length); final EntityId originalEid = factory.getEntityIdFromHBaseRowKey(hbaseRowKey); final JsonEntityIdParser restEid1 = JsonEntityIdParser.create(originalEid, layout); final JsonEntityIdParser restEid2 = JsonEntityIdParser .create(String.format("hbase=%s", Bytes.toStringBinary(hbaseRowKey)), layout); final JsonEntityIdParser restEid3 = JsonEntityIdParser .create(String.format("hbase_hex=%s", new String(Hex.encodeHex((hbaseRowKey)))), layout); // Resolved entity id should match origin entity id. assertEquals(originalEid, restEid1.getEntityId()); assertEquals(originalEid, restEid2.getEntityId()); assertEquals(originalEid, restEid3.getEntityId()); // Component representation of entities should work. final JsonEntityIdParser restEid4 = JsonEntityIdParser.create(SINGLE_COMPONENT_EID, layout); final EntityId resolvedEid = restEid4.getEntityId(); final String recoveredComponent = Bytes.toString(Bytes .toBytesBinary(resolvedEid.toShellString().substring(ToolUtils.FIJI_ROW_KEY_SPEC_PREFIX.length()))); assertEquals(UNUSUAL_STRING_EID, recoveredComponent); assertEquals(resolvedEid, restEid4.getEntityId()); }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.AttachmentUtils.java
private static void inlineData(XmlCursor cursor, SchemaType schemaType, InputStream in) throws IOException { String content = null;//from ww w. java 2 s . co m byte[] data = Tools.readAll(in, -1).toByteArray(); if (SchemaUtils.isInstanceOf(schemaType, XmlHexBinary.type)) { content = new String(Hex.encodeHex(data)); } else if (SchemaUtils.isInstanceOf(schemaType, XmlBase64Binary.type)) { content = new String(Base64.encodeBase64(data)); } XmlCursor c = cursor.newCursor(); c.setTextValue(content); c.dispose(); }
From source file:hudson.plugins.ec2.EC2PrivateKey.java
static String digestOpt(Key k, String dg) throws IOException { try {/* w w w. j av a2 s . com*/ MessageDigest md5 = MessageDigest.getInstance(dg); DigestInputStream in = new DigestInputStream(new ByteArrayInputStream(k.getEncoded()), md5); try { while (in.read(new byte[128]) > 0) ; // simply discard the input } finally { in.close(); } StringBuilder buf = new StringBuilder(); char[] hex = Hex.encodeHex(md5.digest()); for (int i = 0; i < hex.length; i += 2) { if (buf.length() > 0) buf.append(':'); buf.append(hex, i, 2); } return buf.toString(); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.sav.SAVFileReaderSpi.java
@Override public boolean canDecodeInput(File file) throws IOException { if (file == null) { throw new IllegalArgumentException("file == null!"); }/* w w w . j a v a 2 s.c o m*/ if (!file.canRead()) { throw new IOException("cannot read the input file"); } dbgLog.fine("applying the sav test\n"); // set-up a FileChannel instance for a given file object FileChannel srcChannel = new FileInputStream(file).getChannel(); // create a read-only MappedByteBuffer MappedByteBuffer buff = srcChannel.map(FileChannel.MapMode.READ_ONLY, 0, SAV_HEADER_SIZE); //printHexDump(buff, "hex dump of the byte-buffer"); dbgLog.fine("hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(buff.array()))); buff.rewind(); boolean DEBUG = false; byte[] hdr4 = new byte[4]; buff.get(hdr4, 0, 4); String hdr4sav = new String(hdr4); dbgLog.fine("from string[hdr4]=" + new String(Hex.encodeHex(hdr4)).toUpperCase()); if (hdr4sav.equals("$FL2")) { dbgLog.fine("this file is spss-sav type"); return true; } else { dbgLog.fine("this file is NOT spss-sav type"); } return false; }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReaderSpi.java
@Override public boolean canDecodeInput(File file) throws IOException { if (file == null) { throw new IllegalArgumentException("file == null!"); }//from w ww . j av a 2 s.c om if (!file.canRead()) { throw new IOException("cannot read the input file"); } dbgLog.fine("applying the sav test\n"); // set-up a FileChannel instance for a given file object FileChannel srcChannel = new FileInputStream(file).getChannel(); // create a read-only MappedByteBuffer MappedByteBuffer buff = srcChannel.map(FileChannel.MapMode.READ_ONLY, 0, SAV_HEADER_SIZE); //printHexDump(buff, "hex dump of the byte-buffer"); dbgLog.info("hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(buff.array()))); buff.rewind(); boolean DEBUG = false; byte[] hdr4 = new byte[4]; buff.get(hdr4, 0, 4); String hdr4sav = new String(hdr4); dbgLog.fine("from string[hdr4]=" + new String(Hex.encodeHex(hdr4)).toUpperCase()); if (hdr4sav.equals("$FL2")) { dbgLog.fine("this file is spss-sav type"); return true; } else { dbgLog.fine("this file is NOT spss-sav type"); } return false; }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public String generatePassphrase() { SecureRandom random;//from w w w. j a v a 2 s . c o m String passphrase; byte[] buf; try { /* Attempt to get the specified RNG instance */ random = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException nsae) { random = new SecureRandom(); } buf = new byte[10]; random.nextBytes(buf); passphrase = new String(Hex.encodeHex(buf)); return passphrase; }
From source file:com.redhat.rhn.common.util.MD5Crypt.java
/** * MD5 and Hexify an array of bytes. Take the input array, MD5 encodes it * and then turns it into Hex.//from w w w . ja va 2 s . c o m * @param secretBytes you want md5hexed * @return md5hexed String. */ public static String md5Hex(byte[] secretBytes) { String retval = null; // add secret MessageDigest md; try { md = MessageDigest.getInstance("MD5"); //byte[] secretBytes = inputString.getBytes("UTF-8"); md.update(secretBytes); // generate the digest byte[] digest = md.digest(); // hexify this puppy retval = new String(Hex.encodeHex(digest)); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "NoSuchAlgorithm: MD5. Something" + " weird with your JVM, you should be able to do this.", e); } return retval; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator.java
/** * Apply MD5 to this string, and encode as a string of hex digits. Just * right for storing passwords in the database, or hashing the password * link./*from w w w .j a v a2s.c om*/ */ public static String applyMd5Encoding(String raw) { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digest = md.digest(raw.getBytes()); char[] hexChars = Hex.encodeHex(digest); return new String(hexChars).toUpperCase(); } catch (NoSuchAlgorithmException e) { // This can't happen with a normal Java runtime. throw new RuntimeException(e); } }
From source file:com.eviware.soapui.impl.wsdl.support.FileAttachment.java
public InputStream getInputStream() throws IOException { BufferedInputStream inputStream = null; if (isCached()) { ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(config.getData())); zipInputStream.getNextEntry();// w ww. java 2 s. c o m inputStream = new BufferedInputStream(zipInputStream); } else { String url = urlProperty.expand(); inputStream = new BufferedInputStream( url == null ? new ByteArrayInputStream(new byte[0]) : new FileInputStream(url)); } AttachmentEncoding encoding = getEncoding(); if (encoding == AttachmentEncoding.BASE64) { ByteArrayOutputStream data = Tools.readAll(inputStream, Tools.READ_ALL); return new ByteArrayInputStream(Base64.encodeBase64(data.toByteArray())); } else if (encoding == AttachmentEncoding.HEX) { ByteArrayOutputStream data = Tools.readAll(inputStream, Tools.READ_ALL); return new ByteArrayInputStream(new String(Hex.encodeHex(data.toByteArray())).getBytes()); } return inputStream; }
From source file:net.padlocksoftware.padlock.validator.ValidatorTest.java
License:asdf
/** * this test actually only works when there is no padlock license key referenced. Disabling the license * check to enforce a 2 week expiry period breaks this test. Thus I am disabling * /* w ww. ja v a 2s. c o m*/ * @throws Exception */ @Test @Ignore public void testExpired() throws Exception { KeyPair pair = KeyManager.createKeyPair(); License license = LicenseFactory.createLicense(); license.setStartDate(new Date(100)); LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate()); signer.sign(license); String key = new String(Hex.encodeHex(pair.getPublic().getEncoded())); Validator validator = new Validator(license, key); boolean ex = false; try { validator.validate(); } catch (ValidatorException e) { ex = true; } assertTrue(ex); }