List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:net.sheehantech.cherry.ProtocolTest.java
@Test public void binaryEncodeShortEnhanced() throws Exception { String expectedContent = "{\"aps\":{\"alert\":{\"body\":\"Some body\",\"loc-args\":[\"Blah blah\"],\"loc-key\":\"SOMETHING\",\"title\":\"Something\"},\"sound\":\"other.aiff\"},\"command\":\"doit\"}"; NotificationAlert alert = new NotificationAlert(); alert.setTitle("Something"); alert.setBody("Some body"); alert.setLocKey("SOMETHING"); alert.addLocArg("Blah blah"); ExtendedAPSInfo extendedAPSInfo = new ExtendedAPSInfo(); extendedAPSInfo.setAlert(alert);//from w w w .ja v a 2 s.c o m extendedAPSInfo.setSound("other.aiff"); Notification notification = new Notification(); notification.setId(1); notification.setToken("6c2ea18861e0d1ccf521984655c3b6e8660bd2f3daff4e15156a73847a17e647"); notification.setAPS(extendedAPSInfo); notification.addField("command", "doit"); notification.setExpires(new Date()); byte[] encodedPayload = Protocol.legacyEncode(notification); //System.out.println("Length: " + encodedPayload.length); byte[] expected = expectedEnhanced((byte) 1, 1, (int) (notification.getExpires().getTime() / 1000), Hex.decodeHex("6c2ea18861e0d1ccf521984655c3b6e8660bd2f3daff4e15156a73847a17e647".toCharArray()), expectedContent.getBytes()); assertEquals(expected.length, encodedPayload.length); for (int b = 0; b < encodedPayload.length; b++) { //System.out.println("Checking (" + b + ") expected " + expected[b] + " against actual " + encodedPayload[b]); assertEquals(expected[b], encodedPayload[b]); } }
From source file:com.knewton.mapreduce.SSTableColumnMapperTest.java
/** * Test the start time range filters in the mapper. * // w ww . j av a2 s . c om * @throws IOException * @throws InterruptedException * @throws DecoderException */ @Test public void testStartRangeStudentEvents() throws IOException, InterruptedException, DecoderException { // Mar.28.2013.19:53:38.0.0 DateTime dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC); long eventId1 = dt.getMillis(); // Mar.29.2013.03:07:21.0.0 dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC); long eventId5 = dt.getMillis(); ByteBuffer columnName = ByteBuffer.wrap(new byte[8]); columnName.putLong(eventId1); columnName.rewind(); IColumn column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray()))); Configuration conf = new Configuration(); conf.set(StudentEventAbstractMapper.START_DATE_PARAMETER_NAME, "2013-03-28T23:03:02.394-04:00"); DoNothingStudentEventMapper dnsem = new DoNothingStudentEventMapper(); Mapper<ByteBuffer, IColumn, LongWritable, StudentEventWritable>.Context context = dnsem.new Context(conf, new TaskAttemptID(), null, null, null, new DoNothingStatusReporter(), null); dnsem.setup(context); dnsem.map(RandomStudentEventGenerator.getRandomIdBuffer(), column, context); assertNull(dnsem.getRowKey()); columnName = ByteBuffer.wrap(new byte[8]); columnName.putLong(eventId5); columnName.rewind(); column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray()))); ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer(); dnsem.map(randomKey, column, context); assertEquals(dnsem.getRowKey(), randomKey); }
From source file:me.footlights.core.crypto.FingerprintTest.java
private void testVectors(Fingerprint.Builder builder, String[][] testVectors) throws DecoderException { for (String[] vectors : testVectors) { byte[] input = Hex.decodeHex(vectors[0].toCharArray()); byte[] expected = Hex.decodeHex(vectors[1].toCharArray()); Fingerprint fingerprint = builder.setContent(input).build(); byte[] output = new byte[fingerprint.getBytes().remaining()]; fingerprint.getBytes().get(output); assertTrue(fingerprint.matches(expected)); assertArrayEquals(expected, output); assertEquals(vectors[1], fingerprint.hex()); }/* w ww . j a v a 2 s . c om*/ }
From source file:mitm.common.security.certificate.GenerateTestCA.java
private PublicKey decodePublicKey(String encoded) throws Exception { byte[] rawKey = Hex.decodeHex(encoded.toCharArray()); KeySpec keySpec = new X509EncodedKeySpec(rawKey); return keyFactory.generatePublic(keySpec); }
From source file:libepg.epg.section.sdt.ServiceDescriptionTableBodyTest.java
public ServiceDescriptionTableBodyTest() throws DecoderException { byte[] b = Hex.decodeHex( "42f0977fe1d100007fe1ff0408f30020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f00104080409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe080588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32722fa2b5ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" .toCharArray());/*from w w w .ja v a 2 s. c om*/ this.sdth = new ServiceDescriptionTableBody(new Section(b).getSectionBody()); }
From source file:com.google.feedserver.util.EncryptionUtil.java
/** * Decrypts the given encrypted string and returns the original value * /*from ww w .ja v a2 s . co m*/ * @param encryptedValue The encrypted string * @return The decrypted value * @throws InvalidKeyException * @throws BadPaddingException * @throws IllegalBlockSizeException * @throws DecoderException * @throws NoSuchPaddingException * @throws NoSuchAlgorithmException */ public String decrypt(String encryptedValue) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, DecoderException, NoSuchAlgorithmException, NoSuchPaddingException { byte[] encryptionBytes = Hex.decodeHex(encryptedValue.toCharArray()); Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, key); byte[] recoveredBytes = cipher.doFinal(encryptionBytes); String recovered = new String(recoveredBytes); return recovered; }
From source file:com.glaf.core.security.RSAUtils.java
/** * ?//from ww w .j a v a2s . c o m * <p /> * ? {@code null} {@code encrypttext} {@code null} * {@code null} ??? {@code null} * * @param privateKey * ? * @param encrypttext * * @return */ public static String decryptString(PrivateKey privateKey, String encrypttext) { if (privateKey == null || StringUtils.isEmpty(encrypttext)) { return null; } try { byte[] en_data = Hex.decodeHex(encrypttext.toCharArray()); byte[] data = decrypt(privateKey, en_data); return new String(data); } catch (Exception ex) { LOGGER.error( String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getCause().getMessage())); } return null; }
From source file:corner.encrypt.services.impl.DESedeEncryptServiceImpl.java
/** * @see corner.encrypt.services.EncryptService#decrypt(java.lang.String) *//* www.j a v a2 s . co m*/ @Override public String decrypt(final String cryptograph) { if (cryptograph == null) return null; try { // ? byte[] decoded = Hex.decodeHex(cryptograph.toCharArray()); // cryptograph.getBytes(CHIPERH_CHARSET); // byte[] srcBytes = decrypt(decoded, cipher.getCipher()); if (srcBytes == null) return null; return new String(srcBytes, CHIPERH_CHARSET); } catch (Throwable e) { e.printStackTrace(); } return null; }
From source file:com.knewton.mapreduce.util.SerializationUtilsTest.java
/** * Try to get the wrong deserializer from the conf and tries to deserialize some event data with * the wrong TProtocol.//from w w w .j a v a 2 s . c o m * * @throws DecoderException * @throws TException */ @Test(expected = TTransportException.class) public void testDeserializerInstantiationWithWrongDeserializer() throws DecoderException, TException { Configuration conf = new Configuration(); conf.set(SerializationUtils.SERIALIZATION_FACTORY_PARAMETER, TBinaryProtocol.Factory.class.getName()); TDeserializer deserializer = SerializationUtils.getDeserializerFromContext(conf); assertNotNull(deserializer); StudentEventData sed = new StudentEventData(); byte[] studentEventDataBytes = Hex.decodeHex(eventDataString.toCharArray()); deserializer.deserialize(sed, studentEventDataBytes); }
From source file:libepg.epg.section.SectionTest.java
public SectionTest() throws DecoderException { this.section_byte = Hex.decodeHex( "42f0977fe1d100007fe1ff0408f30020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f00104080409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe080588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32722fa2b5ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" .toCharArray());/*from w ww.j a v a2 s. c o m*/ this.testSection_OK = new Section(this.section_byte); }