List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:com.knewton.mapreduce.util.SerializationUtilsTest.java
/** * Test if a deserializer can be instantiated correctly from a Hadoop conf with the default * property./*from ww w .j a va 2s .c o m*/ * * @throws TException * @throws DecoderException */ @Test public void testDefaultDeserializerInstantiation() throws TException, DecoderException { TDeserializer deserializer = SerializationUtils.getDeserializerFromContext(new Configuration()); assertNotNull(deserializer); StudentEventData sed = new StudentEventData(); byte[] studentEventDataBytes = Hex.decodeHex(eventDataString.toCharArray()); deserializer.deserialize(sed, studentEventDataBytes); assertNotNull(sed.getBook()); assertNotNull(sed.getCourse()); assertNotNull(sed.getType()); assertNotEquals(0L, sed.getScore()); assertNotEquals(0L, sed.getStudentId()); assertNotEquals(0L, sed.getTimestamp()); }
From source file:net.sourceforge.jaulp.crypto.aes.HexDump.java
/** * Transform the given array of characters representing hexadecimal values into a String object. * * @param data/*from w w w.j a v a 2 s. co m*/ * the array of characters * @return the decoded string * @throws DecoderException * is thrown if an odd number or illegal of characters is supplied */ public static String decodeHexToString(char[] data) throws DecoderException { return new String(Hex.decodeHex(data)); }
From source file:com.microsoft.sqlserver.jdbc.datatypes.SQLServerSpatialDatatypeTest.java
@Test public void testPointWkb() throws DecoderException { String geoWKT = "POINT(3 40 5 6)"; byte[] geomWKB = Hex.decodeHex( "00000000010F0000000000000840000000000000444000000000000014400000000000001840".toCharArray()); byte[] geogWKB = Hex.decodeHex( "E6100000010F0000000000004440000000000000084000000000000014400000000000001840".toCharArray()); Geometry geomWKT = Geometry.deserialize(geomWKB); Geography geogWKT = Geography.deserialize(geogWKB); assertEquals(geomWKT.asTextZM(), geoWKT); assertEquals(geogWKT.asTextZM(), geoWKT); }
From source file:com.cliqset.magicsig.algorithm.test.HMACSHA256MagicSignatureAlgorithmTest.java
@Test public void testVerifyFailDataDifferent() { try {//www. ja va 2 s .c om SecretKey key = new SecretKey("HMAC-SHA256", Hex.decodeHex(hexKey.toCharArray())); HMACSHA256MagicSigAlgorithm alg = new HMACSHA256MagicSigAlgorithm(); Assert.assertFalse(alg.verify(stringData.substring(1).getBytes("UTF-8"), Hex.decodeHex(hexSig.toCharArray()), key)); } catch (Exception e) { Assert.fail(e.getMessage()); } }
From source file:libepg.epg.section.sectionreconstructor.PayLoadSplitterTest.java
/** * Test of getSplittedPayLoad method, of class PayLoadSplitter. * * @throws org.apache.commons.codec.DecoderException *//*from w w w. j a va2 s.c om*/ @Test public void testGetSplittedPayLoad01() throws DecoderException { LOG.debug("getSplittedPayLoad_ "); TsPacket packet = this.testData.getEit0(); PayLoadSplitter instance = new PayLoadSplitter(); instance.setPacket(packet); Map<PayLoadSplitter.PAYLOAD_PART_KEY, byte[]> expResult = new HashMap<>(); expResult.put(PayLoadSplitter.PAYLOAD_PART_KEY.PREV_POINTER, Hex.decodeHex( "4a2cc0b1ce36753456004e24126a706e1e001cf231693d50fcbdf3ca432ace317c3f3ca44c254e4fcb4777eadeb9fa004e2f226a706e29063d5031693c5421215a3d503169215b4170342240354d3a2124215a386cea215b63264c6e4d243b52005006f1b3006a706e5406a2ff22ff84ffc10184c409f203100fff6f6a706ec70e0008300501136a706e006a706e00d60d13040844f5040944f5040a44f53246fb41" .toCharArray())); expResult.put(PayLoadSplitter.PAYLOAD_PART_KEY.NEXT_POINTER, Hex.decodeHex("4ef2920408d101017fe17fe1014e44f8dfe1233000".toCharArray())); Map<PayLoadSplitter.PAYLOAD_PART_KEY, byte[]> result = instance.getSplittedPayLoad(); assertEquals(expResult.size(), result.size()); Set<PayLoadSplitter.PAYLOAD_PART_KEY> expResKeys = expResult.keySet(); Set<PayLoadSplitter.PAYLOAD_PART_KEY> resKeys = result.keySet(); assertEquals(expResKeys, resKeys); for (PayLoadSplitter.PAYLOAD_PART_KEY key : resKeys) { byte[] expResBytes = expResult.get(key); byte[] ResBytes = result.get(key); assertArrayEquals("?", expResBytes, ResBytes); } }
From source file:libepg.epg.section.SectionCrcCheckerTest.java
/** * Test of checkCrc method, of class SectionCrcChecker. *///from w ww . j av a 2 s. co m @Test public void testCalcCrc2() throws DecoderException { LOG.debug("calcCrc_ng"); byte[] sectionData = Hex.decodeHex( "52f0977fe1d100007fe1ff0408f30020481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f00104080409f3001c481201000f0e4e484b451d461d6c320f456c357ec10184cf0302fe08040af3001c481201000f0e4e484b451d461d6c330f456c357ec10184cf0302fe080588e5001f480ec0000b0e4e484b0f374842530e32c10188cf0a030e4e484b0f215d0e32722fa2b5" .toCharArray()); SectionCrcChecker instance = new SectionCrcChecker(); int expResult = 0; int result = instance.checkCrc(sectionData); assertTrue(expResult != result); }
From source file:com.zimbra.cs.account.TrustedTokenKey.java
private TrustedTokenKey(String k) throws ServiceException { String parts[] = k.split(":"); if (parts.length != 3) throw ServiceException.INVALID_REQUEST("invalid tusted device token key", null); String ver = parts[0];/*from w w w . j a v a 2 s .c om*/ String created = parts[1]; String data = parts[2]; try { mVersion = Long.parseLong(ver); } catch (NumberFormatException e) { throw ServiceException.INVALID_REQUEST("invalid tusted device token key version", e); } try { mCreated = Long.parseLong(created); } catch (NumberFormatException e) { throw ServiceException.INVALID_REQUEST("invalid tusted device token key created data", e); } try { mKey = Hex.decodeHex(data.toCharArray()); } catch (DecoderException e) { throw ServiceException.INVALID_REQUEST("invalid tusted device token key data", e); } }
From source file:com.streamsets.lib.security.http.TestPasswordHasher.java
@Test public void testPasswordHashDefault() throws Exception { Configuration configuration = new Configuration(); configuration.set(PasswordHasher.ITERATIONS_KEY, 1); PasswordHasher hasher = new PasswordHasher(configuration); String currentVersion = hasher.getCurrentVersion(); String passwordHash = hasher.getPasswordHash("user", "foo"); Assert.assertEquals(hasher.getCurrentVersion(), hasher.getHashVersion(passwordHash)); Assert.assertTrue(passwordHash.startsWith(currentVersion + ":" + hasher.getIterations() + ":")); String[] parts = passwordHash.split(":"); Assert.assertEquals(4, parts.length); int iterations = Integer.parseInt(parts[1]); byte[] salt = Hex.decodeHex(parts[2].toCharArray()); PBEKeySpec spec = new PBEKeySpec(hasher.getValueToHash(currentVersion, "user", "foo").toCharArray(), salt, iterations, hasher.getKeyLength()); byte[] hash = PasswordHasher.SECRET_KEY_FACTORIES.get(hasher.getCurrentVersion()).generateSecret(spec) .getEncoded();/*from ww w . java 2s . c o m*/ String hashHex = Hex.encodeHexString(hash); Assert.assertEquals(parts[3], hashHex); //valid u/p Assert.assertTrue(hasher.verify(passwordHash, "user", "foo")); // invalid u valid p, V2 catches this Assert.assertFalse(hasher.verify(passwordHash, "userx", "foo")); // invalid p Assert.assertFalse(hasher.verify(passwordHash, "user", "bar")); }
From source file:com.zimbra.cs.account.ExtAuthTokenKey.java
private ExtAuthTokenKey(String k) throws ServiceException { String parts[] = k.split(":"); if (parts.length != 3) throw ServiceException.INVALID_REQUEST("invalid auth token key", null); String ver = parts[0];/*from www . j a va 2 s .c o m*/ String created = parts[1]; String data = parts[2]; try { version = Long.parseLong(ver); } catch (NumberFormatException e) { throw ServiceException.INVALID_REQUEST("invalid auth token key version", e); } try { this.created = Long.parseLong(created); } catch (NumberFormatException e) { throw ServiceException.INVALID_REQUEST("invalid auth token key created data", e); } try { key = Hex.decodeHex(data.toCharArray()); } catch (DecoderException e) { throw ServiceException.INVALID_REQUEST("invalid auth token key data", e); } }
From source file:be.fedict.hsm.model.security.ApplicationSecurityBean.java
/** * Authenticates a given credential as a certain application. * // w ww. j a va 2 s . c o m * @param username * the credential fingerprint. * @param encodedCredential * the actual credential. * @return the authenticated application identifier. */ public String getAuthenticatedApplication(String username, char[] encodedCredential) { LOG.debug("authenticating " + username); CredentialEntity credentialEntity = this.entityManager.find(CredentialEntity.class, username); if (null == credentialEntity) { LOG.warn("unknown application credential: " + username); this.securityAuditGeneratorBean.webServiceAuthenticationError(); return null; } byte[] credential; try { credential = Hex.decodeHex(encodedCredential); } catch (DecoderException e) { LOG.error("error decoding credential"); this.securityAuditGeneratorBean.webServiceAuthenticationError(username); return null; } byte[] expectedCredential = credentialEntity.getCredential(); if (false == Arrays.equals(expectedCredential, credential)) { LOG.error("credential mismatch"); this.securityAuditGeneratorBean.webServiceAuthenticationError(username); return null; } LOG.debug("credential matches"); ApplicationEntity applicationEntity = credentialEntity.getApplication(); LOG.debug("application id: " + applicationEntity.getId()); return Long.toString(applicationEntity.getId()); }