List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:com.jejking.hh.nord.corpus.AllrisHtmlToRawDrucksache.java
private URL originalUrlFromFileName(File file) throws MalformedURLException, DecoderException { String hexName = file.getName().substring(0, file.getName().length() - 3); // trim off ".gz" URL originalUrl = new URL(new String(Hex.decodeHex(hexName.toCharArray()), Charsets.UTF_8)); return originalUrl; }
From source file:com.facebook.presto.accumulo.iterators.SingleColumnValueFilter.java
@Override public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException { super.init(source, options, env); columnFamily = new Text(options.get(CF)); columnQualifier = new Text(options.get(CQ)); compareOp = CompareOp.valueOf(options.get(COMPARE_OP)); try {//from w w w. java2 s .c om value = new Value(Hex.decodeHex(options.get(VALUE).toCharArray())); } catch (DecoderException e) { // should not occur, as validateOptions tries this same thing throw new IllegalArgumentException("Error decoding hex value in option", e); } }
From source file:mitm.common.security.certificate.GenerateTestCA.java
private PrivateKey decodePrivateKey(String encoded) throws Exception { byte[] rawKey = Hex.decodeHex(encoded.toCharArray()); KeySpec keySpec = new PKCS8EncodedKeySpec(rawKey); return keyFactory.generatePrivate(keySpec); }
From source file:com.romeikat.datamessie.core.base.service.AuthenticationServiceTest.java
@Test public void authenticate_failHash() throws DecoderException { final String password = "test"; final String passwordSalt = "27dc26310555341f18bb1c551550df98dd36fcde224c7fd6ddb25f9f6948c924aad52067ee6e8d82aeff57250cefd5064598c4b753331dfc44550cc982d37292"; final String wrongPasswordHash = "00"; final byte[] passwordSaltBytes = Hex.decodeHex(passwordSalt.toCharArray()); final byte[] passwordHashBytes = Hex.decodeHex(wrongPasswordHash.toCharArray()); final boolean authenticated = authenticationService.authenticate(password, passwordSaltBytes, passwordHashBytes);/* w w w . j a v a 2s .c om*/ assertFalse(authenticated); }
From source file:com.vmware.identity.rest.core.util.RequestSigner.java
/** * Verify a signed request using a hex-formatted string, the string to sign, and a certificate's public key. * * @param signedRequestHex a hex-encoded string representing the signed request to verify. * @param stringToSign the string that will be signed with the public key for * verification purposes.//from ww w. j a va 2 s .c o m * @param publicKey the public key used for verification. * @return true if the signature was verified, false if not. * @throws DecoderException if there is an error decoding the hex string. * @throws InvalidKeyException if the public key is invalid. * @throws SignatureException if the signature algorithm is unable to process the input * data provided. */ public static boolean verify(String signedRequestHex, String stringToSign, PublicKey publicKey) throws DecoderException, InvalidKeyException, SignatureException { byte[] signedRequest = Hex.decodeHex(signedRequestHex.toCharArray()); Signature sig; try { sig = Signature.getInstance(SHA256_WITH_RSA); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("An error occurred while getting the signature algorithm", e); } sig.initVerify(publicKey); sig.update(stringToSign.getBytes(StandardCharsets.UTF_8)); return sig.verify(signedRequest); }
From source file:com.netflix.imfutility.itunes.image.ImageValidator.java
private static byte[] getBytes(String hexString) { if (StringUtils.isBlank(hexString)) { return new byte[] {}; }// www. j av a 2 s . co m try { return Hex.decodeHex(hexString.toCharArray()); } catch (DecoderException e) { throw new RuntimeException(e); } }
From source file:me.schiz.jmeter.ring.udp.sampler.UDPRingSampler.java
@Override public SampleResult sample(Entry entry) { boolean idling = false; SampleResult newSampleResult = new SampleResult(); newSampleResult.setSampleLabel(getName()); ConcurrentLinkedQueue<SampleResult> queue = tlQueue.get(); if (queue == null) { queue = new ConcurrentLinkedQueue<SampleResult>(); tlQueue.set(queue);//w w w . java 2 s .c o m } Ring ring = UDPRingSourceElement.get(getSource()); Token t; int tid = -1; byte[] request_in_bytes = new byte[0]; ByteBuffer request = tlRequest.get(); if (request == null) { request = tlBuffer.get(); if (request == null) { request = ByteBuffer.allocateDirect(8 * 1024 * 1024); tlBuffer.set(request); } request.clear(); if (isHex()) { try { request_in_bytes = Hex.decodeHex(getRequest().toCharArray()); } catch (DecoderException e) { log.error("can't decode request", e); idling = true; } } else { request_in_bytes = getRequest().getBytes(); } request.put(request_in_bytes); } if (!idling) { try { request.flip(); while (tid == -1) { tid = ring.acquire(); } t = ring.get(tid); t.lock.lock(); if (isHex()) t.ishex = true; newSampleResult.sampleStart(); try { //t.socketChannel.write(request); t.sampleResult = newSampleResult; t.queue = queue; ring.write(tid, request); request.clear(); newSampleResult.setSuccessful(true); } catch (IOException e) { newSampleResult.setSuccessful(false); ring.reset(tid); log.warn("IOException", e); } finally { t.lock.unlock(); } } catch (Exception e) { log.error("Exception", e); newSampleResult.setSuccessful(false); newSampleResult.setResponseCode(e.getClass().getName()); while (!queue.offer(newSampleResult)) { } if (tid != -1) ring.reset(tid); } finally { newSampleResult.setRequestHeaders(getRequest()); } } SampleResult sampleResult = queue.poll(); return sampleResult; }
From source file:ai.serotonin.backup.Restore.java
File decryptFile(final File encryptedFile) throws Exception { String filename = encryptedFile.getName(); int pos = filename.indexOf('_'); final String saltStr = filename.substring(0, pos); final byte[] salt = Hex.decodeHex(saltStr.toCharArray()); filename = filename.substring(pos + 1); pos = filename.indexOf('_'); final String ivStr = filename.substring(0, pos); final byte[] iv = Hex.decodeHex(ivStr.toCharArray()); filename = filename.substring(pos + 1); final File file = new File(filename); final SecretKey secret = createSecretKey(salt); final Cipher cipher = createCipher(); cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv)); cipherizeFile(encryptedFile, file, cipher); LOG.info("Decrypted archive to " + filename); return file;/*from w w w . j ava 2 s. co m*/ }
From source file:com.cliqset.magicsig.algorithm.test.HMACSHA256MagicSignatureAlgorithmTest.java
@Test public void testInvalidKeyAlgorithm() { try {//from www . j a va 2 s . co m SecretKey key = new SecretKey("HMAC-SHA1", Hex.decodeHex(hexKey.toCharArray())); HMACSHA256MagicSigAlgorithm alg = new HMACSHA256MagicSigAlgorithm(); alg.verify(stringData.substring(1).getBytes("UTF-8"), Hex.decodeHex(hexSig.toCharArray()), key); Assert.fail(); } catch (MagicSigException mse) { Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.getMessage()); } }
From source file:it.scoppelletti.programmerpower.security.spi.RC2ParameterSpecFactory.java
public AlgorithmParameterSpec newInstance(Properties props, String prefix) { int keySize;//from ww w . ja v a 2s . c o m String name, value; byte[] iv; AlgorithmParameterSpec param; name = Strings.concat(prefix, RC2ParameterSpecFactory.PROP_KEYSIZE); value = props.getProperty(name); if (Strings.isNullOrEmpty(value)) { throw new ArgumentNullException(name); } keySize = Integer.parseInt(value); name = Strings.concat(prefix, RC2ParameterSpecFactory.PROP_IV); value = props.getProperty(name); if (Strings.isNullOrEmpty(value)) { iv = null; } else { try { iv = Hex.decodeHex(value.toCharArray()); } catch (DecoderException ex) { throw SecurityUtils.toSecurityException(ex); } } if (iv != null) { param = new RC2ParameterSpec(keySize, iv); } else { param = new RC2ParameterSpec(keySize); } return param; }