List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:com.github.aelstad.keccakj.fips202.KeccackDigestTestUtils.java
public List<DigestTest> parseTests(InputStream is) throws Exception { List<DigestTest> rv = new ArrayList<DigestTest>(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line;// ww w. j av a2s. co m DigestTest nextTest = new DigestTest(); while ((line = br.readLine()) != null) { String token = null; String value = null; if (line.contains("=")) { token = line.split("=")[0].replace(" ", ""); value = line.split("=")[1].replace(" ", ""); } if (token != null && value != null && token.length() > 0 && value.length() > 0) { if (token.equalsIgnoreCase("len")) { nextTest.len = Integer.parseInt(value); } else if (token.equalsIgnoreCase("msg")) { nextTest.msg = Hex.decodeHex(value.toCharArray()); } else if (token.equalsIgnoreCase("MD") || token.equalsIgnoreCase("Squeezed")) { nextTest.digest = Hex.decodeHex(value.toCharArray()); } if (nextTest.len >= 0 && nextTest.msg != null && nextTest.digest != null) { rv.add(nextTest); nextTest = new DigestTest(); } } } return rv; }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoEncodingService.java
/** * * @param hex//from ww w . j a v a 2s. c o m * @return * @throws DecoderException */ public String hexToBase64(String hex) throws DecoderException { String b64data = new String(Base64.encodeBase64(Hex.decodeHex(hex.toCharArray()))); return b64data; }
From source file:edu.tamu.tcat.crypto.bouncycastle.SecureTokenImpl.java
/** * Create a new token generator/parser using an encryption key. This attempts to fail early by creating a cipher in the constructor. * @param hexKey The encryption key, hex encoded. ATM, this uses AES, so 128, 194, or 256 bit * @throws TokenException Thrown if the key or IV are not properly base64 encoded or the cipher cannot otherwise be created. *//* w w w.j a v a2s . c om*/ public SecureTokenImpl(String hexKey) throws TokenException { try { byte[] keyBytes = Hex.decodeHex(hexKey.toCharArray()); key = new SecretKeySpec(keyBytes, "AES"); createCipher(Cipher.ENCRYPT_MODE, createIV()); } catch (DecoderException e) { throw new TokenException("Invalid Key or IV", e); } }
From source file:com.qubole.quark.catalog.db.encryption.AESEncrypt.java
public String convertToEntityAttribute(String phrase) throws SQLException { try {/* w w w . j av a 2 s . c o m*/ Cipher decryptCipher = Cipher.getInstance("AES"); decryptCipher.init(Cipher.DECRYPT_MODE, generateMySQLAESKey(this.key, "UTF-8")); return new String(decryptCipher.doFinal(Hex.decodeHex(phrase.toCharArray()))); } catch (Exception e) { throw new SQLException(e); } }
From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.ObjectSerializeUserType.java
/** * JDBC ResultSet??,??/*from w ww .ja va 2 s . c o m*/ * (?null?) * names???? * * @param names * @param owner * @return * @throws HibernateException * @throws SQLException */ @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { ObjectInputStream ois = null; try { String hexStr = rs.getString(names[0]); ois = new ObjectInputStream(new ByteArrayInputStream(Hex.decodeHex(hexStr.toCharArray()))); return ois.readObject(); } catch (Exception e) { throw new HibernateException(e); } finally { try { ois.close(); } catch (IOException e) { } } }
From source file:libepg.util.bytearray.ByteDataBlockTest.java
/** * Test of hashCode method, of class ByteDataBlock. *///from w w w . ja v a2s . c o m @Test public void testHashCode() throws DecoderException { LOG.debug("hashCode"); ByteDataBlock instance1 = new ByteDataBlock(Hex.decodeHex(dat.p0d)); ByteDataBlock instance2 = new ByteDataBlock(Hex.decodeHex(dat.p0d)); assertTrue((instance1.hashCode() == instance2.hashCode())); ByteDataBlock instance5 = new ByteDataBlock(Hex.decodeHex(dat.p0d)); ByteDataBlock instance6 = new ByteDataBlock(Hex.decodeHex(dat.p0e)); assertTrue((instance5.hashCode() != instance6.hashCode())); }
From source file:com.romeikat.datamessie.core.base.service.AuthenticationServiceTest.java
@Test public void authenticate_success() throws DecoderException { final String password = "test"; final String passwordSalt = "27dc26310555341f18bb1c551550df98dd36fcde224c7fd6ddb25f9f6948c924aad52067ee6e8d82aeff57250cefd5064598c4b753331dfc44550cc982d37292"; final String passwordHash = "e42f3bea3fca8b5c03af1ef5a069994a73445267d52e486eebccce0ba268fc3ae8fb22ca9616ced487f0f777d2b631e4f7078b97e5e2e85e1eea99c0d98cc95f"; final byte[] passwordSaltBytes = Hex.decodeHex(passwordSalt.toCharArray()); final byte[] passwordHashBytes = Hex.decodeHex(passwordHash.toCharArray()); final boolean authenticated = authenticationService.authenticate(password, passwordSaltBytes, passwordHashBytes);/*from ww w . ja v a2 s. com*/ assertTrue(authenticated); }
From source file:com.haulmont.cuba.web.test.PasswordEncryptionTest.java
protected String decryptPassword(String password) { SecretKeySpec key = new SecretKeySpec(PASSWORD_KEY.getBytes(), "DES"); IvParameterSpec ivSpec = new IvParameterSpec(PASSWORD_KEY.getBytes()); String result;/*from w w w .j a va 2 s . c o m*/ try { Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key, ivSpec); result = new String(cipher.doFinal(Hex.decodeHex(password.toCharArray()))); } catch (Exception e) { throw new RuntimeException(e); } return result; }
From source file:com.mastercard.mobile_api.utils.Tlv.java
/** * Creates a Tlv byte array from a tag and a value. Length is calculated. * Data Input is in Hex String// w ww . j a va 2s . c om * * @param tag the Tlv tag (HEX String) * @param value the Tlv value (HEX String) * @return the Tlv byte array (HEX String) */ public static String create(String tag, String value) { byte[] bValue = new byte[0]; try { bValue = Hex.decodeHex(value.toCharArray()); } catch (DecoderException e) { e.printStackTrace(); } byte[] bLength = lengthBytes(bValue); String length = new String(Hex.encodeHex(bLength)); return (tag + length + value).toUpperCase(); }
From source file:com.cliqset.magicsig.algorithm.test.RSASHA256MagicSignatureAlgorithmTest.java
@Test public void testVerifySuccess() { try {/*from w w w . j a v a 2 s .c o m*/ MagicKey key = new MagicKey(magicKey.getBytes("ASCII")); RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm(); Assert.assertTrue(alg.verify(stringData.getBytes("UTF-8"), Hex.decodeHex(hexSig.toCharArray()), key)); } catch (Exception e) { Assert.fail(e.getMessage()); } }