List of usage examples for org.apache.commons.codec.binary Hex decode
public Object decode(Object object) throws ClassCastException
From source file:Main.java
public static List<byte[]> hexToListBytesArray(String s) throws DecoderException { List<String> listHex = new ArrayList<String>(); if (s.length() == 2) { listHex.add(s);//from ww w . j ava 2 s . c o m } else if (s.length() > 2 && ((s.length() % 2) == 0)) { for (int i = 0; i < s.length(); i++) { String ss = s.substring(i, i + 2); i = i + 1; listHex.add(ss); } } else { return null; } Hex hex = new Hex(); List<byte[]> listByteArray = new ArrayList<byte[]>(); for (String sh : listHex) { listByteArray.add(hex.decode(sh.getBytes())); } return listByteArray; }
From source file:com.anyi.gp.license.RegisterTools.java
public static String decodeString(String encodedStr) { String encodeStr = "$#TGDF*FAA&21we@VGXD532w23413!"; String tempStr = ""; try {//from w ww. jav a2s. co m if (encodedStr == null) { encodedStr = ""; } //encodedStr = new String(Hex.decodeHex(encodedStr.toCharArray())); Hex hex = new Hex(); encodedStr = new String(hex.decode(encodedStr.getBytes("GBK")), "GBK"); int i = 0; int j = 0; for (i = 0; i < encodedStr.length(); i++) { if (j >= encodeStr.length()) { j = 0; } char truePass = (char) ~(encodedStr.charAt(i) ^ ~encodeStr.charAt(j)); tempStr = tempStr + truePass; j++; } } catch (Exception ex) { throw new RuntimeException(ex.getMessage()); } return tempStr; }
From source file:com.lightboxtechnologies.spectrum.HexWritableTest.java
@Test public void toStringTest() throws Exception { final Hex hex = new Hex(); final String str = "DEADBEEF"; final HexWritable hw = new HexWritable(hex.decode(str.getBytes())); assertEquals(str, hw.toString().toUpperCase()); }
From source file:com.lightboxtechnologies.spectrum.FsEntryUtilsTest.java
@Test public void retrieveImageID() throws Exception { final Hex hex = new Hex(); final byte[] hash = hex.decode("8a9111fe05f9815fc55c728137c5b389".getBytes()); final byte[] key = makeFsEntryKey(hash, "/howdy/doody.jpg".getBytes(), 34); assertArrayEquals(hash, getImageID(key)); }
From source file:com.lightboxtechnologies.spectrum.ImmutableHexWritableTest.java
@Test public void toStringTest() throws Exception { final Hex hex = new Hex(); final String str = "DEADBEEF"; final ImmutableHexWritable ihw = new ImmutableHexWritable(hex.decode(str.getBytes())); assertEquals(str, ihw.toString().toUpperCase()); }
From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java
@Test public void retrieveMD5() throws Exception { final Hex hex = new Hex(); final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeef".getBytes()); final byte[] entryID = FsEntryUtils.makeFsEntryKey( hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17); final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.MD5, entryID); assertArrayEquals(hash, KeyUtils.getHash(rowKey)); }
From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java
@Test public void getHashLengthMD5() throws Exception { final Hex hex = new Hex(); final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeef".getBytes()); final byte[] entryID = FsEntryUtils.makeFsEntryKey( hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17); final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.MD5, entryID); assertEquals(KeyUtils.MD5_LEN, KeyUtils.getHashLength(rowKey)); }
From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java
@Test public void retrieveSHA1() throws Exception { final Hex hex = new Hex(); final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".getBytes()); final byte[] entryID = FsEntryUtils.makeFsEntryKey( hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17); final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.SHA1, entryID); assertArrayEquals(hash, KeyUtils.getHash(rowKey)); }
From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java
@Test public void getHashLengthSHA1() throws Exception { final Hex hex = new Hex(); final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".getBytes()); final byte[] entryID = FsEntryUtils.makeFsEntryKey( hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17); final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.SHA1, entryID); assertEquals(KeyUtils.SHA1_LEN, KeyUtils.getHashLength(rowKey)); }
From source file:com.lightboxtechnologies.spectrum.KeyUtilsTest.java
@Test public void retrieveFsEntryID() throws Exception { final Hex hex = new Hex(); final byte[] hash = hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".getBytes()); final byte[] entryID = FsEntryUtils.makeFsEntryKey( hex.decode("baadf00dbaadf00dbaadf00dbaadf00d".getBytes()), "/etc/passwd".getBytes(), 17); final byte[] rowKey = KeyUtils.makeEntryKey(hash, KeyUtils.SHA1, entryID); assertArrayEquals(entryID, KeyUtils.getFsEntryID(rowKey)); }