List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:net.solarnetwork.node.support.DataCollectorSerialPortBeanParameters.java
public String getMagicHex() { if (getMagic() == null) { return null; } return Hex.encodeHexString(getMagic()); }
From source file:com.thoughtworks.go.server.domain.user.PipelineSelections.java
private String sha256(byte[] bytes) { MessageDigest md;// w ww . j a v a 2 s.c o m try { md = MessageDigest.getInstance(HASH_ALGORITHM); } catch (NoSuchAlgorithmException ignored) { return null; // Using standard algorithm that is required to exist } md.update(bytes); return Hex.encodeHexString(md.digest()); }
From source file:libepg.util.bytearray.ByteArraySplitterTest.java
/** * Test of splitByLengthField method, of class ByteArraySplitter. * * @throws org.apache.commons.codec.DecoderException *//* w ww. j a v a 2 s . co m*/ @Test public void testSplitByLengthField_3args() throws DecoderException { LOG.debug("splitByLengthField"); byte[] src = Hex.decodeHex( "0408f30020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f00104080409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe080588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32" .toCharArray()); int lengthFieldPosition = 4; int lengthFieldLength = 2; List<byte[]> expResult = new ArrayList<>(); expResult.add(Hex.decodeHex( "0408f30020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f0010408".toCharArray())); expResult.add( Hex.decodeHex("0409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08".toCharArray())); expResult.add( Hex.decodeHex("040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe08".toCharArray())); expResult.add(Hex.decodeHex( "0588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32".toCharArray())); List<byte[]> result = ByteArraySplitter.splitByLengthField(src, lengthFieldPosition, lengthFieldLength);//?????????4????0??????????? Iterator<byte[]> it_result = result.iterator(); Iterator<byte[]> it_expResult = expResult.iterator(); while (it_result.hasNext() && it_expResult.hasNext()) { StringBuilder s = new StringBuilder(); byte[] res = it_result.next(); byte[] expRes = it_expResult.next(); if (Arrays.equals(res, expRes) == false) { fail("???????"); } else { s.append(Hex.encodeHexString(expRes)); s.append(" = "); s.append(Hex.encodeHexString(res)); LOG.debug(s.toString()); } } }
From source file:com.demandware.vulnapp.challenge.impl.ECBOracleChallenge.java
/** * encrypt the given input with this object's cipher * //from w w w . ja va2s . c om * @return base64 encoded string of the encrypted value * @throws UnsupportedEncodingException * @throws IllegalBlockSizeException * @throws BadPaddingException */ private String encryptValue(String input) throws UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException { input = input.trim(); byte[] inputBytes = input.getBytes(); int paddedSize = inputBytes.length + (16 - (inputBytes.length % 16)); inputBytes = Arrays.copyOf(inputBytes, paddedSize); byte[] enc = this.eCipher.doFinal(inputBytes); return Hex.encodeHexString(enc); }
From source file:de.phoenix.security.Encrypter.java
/** * Salt a given password with a random salt * //from ww w . j av a 2s . co m * @param password * The password to salt * @param salt * The random generated salt * @param iterations * The number of iterations the password is salted by the * algorithmn * @param bytes * How many bytes the passwords contains * @return A salted password * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ private SaltedPassword saltPassword(char[] password, byte[] salt, int iterations, int bytes) throws NoSuchAlgorithmException, InvalidKeySpecException { PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8); SecretKeyFactory skf = SecretKeyFactory.getInstance(KEY_ALGORITHM); String saltString = Hex.encodeHexString(salt); String saltedHash = Hex.encodeHexString(skf.generateSecret(spec).getEncoded()); return new SaltedPassword(saltedHash, saltString, iterations); }
From source file:io.undertow.servlet.test.streams.ServletInputStreamTestCase.java
private void runTestViaJavaImpl(final String message, String url) throws IOException { HttpURLConnection urlcon = null; try {/*from w w w . j a v a 2s .c o m*/ String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + url; urlcon = (HttpURLConnection) new URL(uri).openConnection(); urlcon.setInstanceFollowRedirects(true); urlcon.setRequestProperty("Connection", "close"); urlcon.setRequestMethod("POST"); urlcon.setDoInput(true); urlcon.setDoOutput(true); OutputStream os = urlcon.getOutputStream(); os.write(message.getBytes()); os.close(); Assert.assertEquals(StatusCodes.OK, urlcon.getResponseCode()); InputStream is = urlcon.getInputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); byte[] buf = new byte[256]; int len; while ((len = is.read(buf)) > 0) { bytes.write(buf, 0, len); } is.close(); final String response = new String(bytes.toByteArray(), 0, bytes.size()); if (!message.equals(response)) { System.out.println(String.format("response=%s", Hex.encodeHexString(response.getBytes()))); } Assert.assertEquals(message, response); } finally { if (urlcon != null) { urlcon.disconnect(); } } }
From source file:com.moz.fiji.schema.tools.TestGetTool.java
@Test public void testGetFromTableMore() throws Exception { final Fiji fiji = getFiji(); final FijiTableLayout layout = FijiTableLayouts.getTableLayout(FijiTableLayouts.FOO_TEST); final long timestamp = 10L; new InstanceBuilder(fiji).withTable(layout.getName(), layout).withRow("gwu@usermail.example.com") .withFamily("info").withQualifier("email").withValue(timestamp, "gwu@usermail.example.com") .withQualifier("name").withValue(timestamp, "Garrett Wu").withRow("aaron@usermail.example.com") .withFamily("info").withQualifier("email").withValue(timestamp, "aaron@usermail.example.com") .withQualifier("name").withValue(timestamp, "Aaron Kimball") .withRow("christophe@usermail.example.com").withFamily("info").withQualifier("email") .withValue(timestamp, "christophe@usermail.example.com").withQualifier("name") .withValue(timestamp, "Christophe Bisciglia").withRow("kiyan@usermail.example.com") .withFamily("info").withQualifier("email").withValue(timestamp, "kiyan@usermail.example.com") .withQualifier("name").withValue(timestamp, "Kiyan Ahmadizadeh").withRow("john.doe@gmail.com") .withFamily("info").withQualifier("email").withValue(timestamp, "john.doe@gmail.com") .withQualifier("name").withValue(timestamp, "John Doe").withRow("jane.doe@gmail.com") .withFamily("info").withQualifier("email").withValue(timestamp, "jane.doe@gmail.com") .withQualifier("name").withValue(timestamp, "Jane Doe").build(); final FijiTable table = fiji.openTable(layout.getName()); try {/*from w w w. ja v a 2 s .co m*/ assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(), "--entity-id=[\"jane.doe@gmail.com\"]")); assertEquals(5, mToolOutputLines.length); EntityId eid = EntityIdFactory.getFactory(layout).getEntityId("gwu@usermail.example.com"); String hbaseRowKey = Hex.encodeHexString(eid.getHBaseRowKey()); assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI() + "info:name", "--entity-id=hbase=hex:" + hbaseRowKey)); assertEquals(3, mToolOutputLines.length); // TODO: Validate GetTool output } finally { ResourceUtils.releaseOrLog(table); } }
From source file:de.taimos.dvalin.interconnect.model.MessageCryptoUtil.java
private static void generateKey() { try {/*ww w .j a v a 2s .com*/ final KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); final SecretKey skey = kgen.generateKey(); System.out.println("Key: " + Hex.encodeHexString(skey.getEncoded())); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } }
From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java
/** * Converts an array of bytes into a string representing the hexadecimal bytes values. * * @param src/* w w w. ja va 2s . com*/ * byte sequence to encode * @return encoded bytes hex string */ public static String encodeHex(byte[] src) { return Hex.encodeHexString(src); }
From source file:com.smartsheet.api.internal.util.StreamUtil.java
/** * generate a String of UTF-8 characters (or hex-digits if byteStream isn't UTF-8 chars) from byteStream, * truncating to maxLen (with "..." added if the result is truncated) * @param byteStream the source of bytes to be converted to a UTF-8 String * @param maxLen the point at which to truncate the string (-1 means don't truncate) in which case "..." is appended * @return the String read from the stream *///from w w w . j a v a 2s .c om public static String toUtf8StringOrHex(ByteArrayOutputStream byteStream, int maxLen) { if (maxLen == -1) { maxLen = Integer.MAX_VALUE; } String result; try { result = byteStream.toString("UTF-8"); } catch (Exception notUtf8) { result = Hex.encodeHexString(byteStream.toByteArray()); } final int resultLen = result != null ? result.length() : 0; final String suffix = resultLen > maxLen ? "..." : ""; return resultLen == 0 ? "" : result.substring(0, Math.min(resultLen, maxLen)) + suffix; }