List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:com.adyen.Util.HMACValidator.java
public String calculateHMAC(String data, String key) throws java.security.SignatureException { try {// w w w . java2 s . c o m byte[] rawKey = Hex.decodeHex(key.toCharArray()); // Create an hmac_sha256 key from the raw key bytes SecretKeySpec signingKey = new SecretKeySpec(rawKey, HMAC_SHA256_ALGORITHM); // Get an hmac_sha256 Mac instance and initialize with the signing // key Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM); mac.init(signingKey); // Compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(data.getBytes(C_UTF8)); // Base64-encode the hmac return new String(Base64.encodeBase64(rawHmac)); } catch (Exception e) { throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } }
From source file:com.feedzai.commons.sql.abstraction.util.AESHelper.java
/** * Decrypts a string encrypted by {@link #encrypt} method. * * @param c The encrypted HEX string.//from www . j a va2 s.c o m * @param key The key. * @return The decrypted string. */ public static String decrypt(String c, String key) { try { SecretKeySpec skeySpec = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] decoded = cipher.doFinal(Hex.decodeHex(c.toCharArray())); return new String(decoded); } catch (Exception e) { logger.warn("Could not decrypt string", e); return null; } }
From source file:eu.europa.ejusticeportal.dss.common.CardDetectionTest.java
@Before public void setUp() throws DecoderException { byteAtrLuxTrust = Hex.decodeHex("3b7d94000080318065b08302047e83009000".toCharArray()); }
From source file:ch.rgw.tools.PasswordEncryptionService.java
public boolean authenticate(String attemptedPassword, String encryptedPassword, String salt) throws NoSuchAlgorithmException, InvalidKeySpecException, DecoderException { return authenticate(attemptedPassword, Hex.decodeHex(encryptedPassword.toCharArray()), Hex.decodeHex(salt.toCharArray())); }
From source file:libepg.epg.section.body.networkinformationtable.TransportStreamLoopTest.java
public TransportStreamLoopTest() throws DecoderException { data1 = Hex.decodeHex("40100004f024411500970100980100990102f1c002f3c002f4c002f5c0430b011727481100e802886008" .toCharArray());/* ww w .j av a 2 s .c om*/ data2 = Hex.decodeHex( "40110004f021411200a10100a20100a30100a9a102fec00300c0430b011727481100e802886008".toCharArray()); target1 = new TransportStreamLoop(this.data1); this.target1_2 = new TransportStreamLoop(this.data1); target2 = new TransportStreamLoop(this.data2); }
From source file:de.drop_converter.plugins.binary_convert.Hex2Data.java
@Override public boolean importData(TransferSupport support) throws ConverterException { try {/*from ww w. ja va 2 s . c o m*/ if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> files = (List<File>) support.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); for (File file : files) { FileInputStream fis = null; OutputStream out = null; try { out = getOutputStream(file, ".hex"); fis = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int count = 0; while (-1 != (count = fis.read(buffer))) { if (count == bufferSize) { out.write(Hex.decodeHex(new String(buffer).toCharArray())); } else { byte[] tmp = Arrays.copyOf(Hex.decodeHex(new String(buffer).toCharArray()), count); out.write(tmp); } } } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(fis); } } return true; } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) { String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); OutputStream out = null; try { byte[] encode = Hex.decodeHex(data.toCharArray()); out = getOutputStream(null, ".hex"); out.write(encode); } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); } } } catch (Exception e) { throw new ConverterException(e); } return false; }
From source file:com.sirius.utils.encrypt.DESEncryptor.java
@Override public String decryptHex(Object key, String data) throws EncryptException { try {/*from w ww. j av a2 s . c om*/ byte[] target = Hex.decodeHex(data.toCharArray()); byte[] result = decrypt(key, target); return new String(result); } catch (Exception e) { throw new EncryptException(e); } }
From source file:info.bonjean.beluga.util.CryptoUtil.java
public static String pandoraDecrypt(String text) { try {/*from w w w . jav a2 s . co m*/ return new String(decryptBlowfish(Hex.decodeHex(text.toCharArray()), DECRYPT_KEY)).trim(); } catch (DecoderException e) { log.error(e.getMessage(), e); return null; } }
From source file:com.buaa.cfs.fs.XAttrCodec.java
/** * Decode string representation of a value and check whether it's encoded. If the given string begins with 0x or 0X, * it expresses a hexadecimal number. If the given string begins with 0s or 0S, base64 encoding is expected. If the * given string is enclosed in double quotes, the inner string is treated as text. Otherwise the given string is * treated as text./* w w w . j a v a 2 s .co m*/ * * @param value string representation of the value. * * @return byte[] the value * * @throws IOException */ public static byte[] decodeValue(String value) throws IOException { byte[] result = null; if (value != null) { if (value.length() >= 2) { String en = value.substring(0, 2); if (value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); result = value.getBytes("utf-8"); } else if (en.equalsIgnoreCase(HEX_PREFIX)) { value = value.substring(2, value.length()); try { result = Hex.decodeHex(value.toCharArray()); } catch (DecoderException e) { throw new IOException(e); } } else if (en.equalsIgnoreCase(BASE64_PREFIX)) { value = value.substring(2, value.length()); result = base64.decode(value); } } if (result == null) { result = value.getBytes("utf-8"); } } return result; }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.AbstractBuilder.java
public static StaticBuffer decodeKey(String name) { try {/* w w w .j av a2 s. c om*/ return new StaticArrayBuffer(Hex.decodeHex(name.toCharArray())); } catch (DecoderException e) { throw new RuntimeException(e); } }