List of usage examples for org.apache.commons.codec.binary Hex encodeHex
protected static char[] encodeHex(byte[] data, char[] toDigits)
From source file:experts.net.nic.MACAddr.java
/** * Converts a byte array contains a hardware address to a String of the form: %x:%x:%x:%x:%x:%x *///from w w w . j a v a2s .c o m private static final String format(byte[] macAddr) { // Converting to a String MAC address obtained StringBuilder sb = new StringBuilder().append(Hex.encodeHex(macAddr, false)); for (int i = 2; i < 17; i += 3) { sb.insert(i, ':'); } // for return sb.toString(); }
From source file:me.figo.internal.FigoTrustManager.java
private static String getThumbPrint(X509Certificate cert) { try {/*from w w w .j a v a 2 s . co m*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] der = cert.getEncoded(); md.update(der); byte[] digest = md.digest(); return new String(Hex.encodeHex(digest, false)); } catch (NoSuchAlgorithmException e) { return ""; } catch (CertificateEncodingException e) { return ""; } }
From source file:de.alpharogroup.crypto.aes.HexDump.java
/** * Transform the given array of bytes into an array of characters representing the hexadecimal * values of each byte in order./*w w w . j a va2 s .com*/ * * @param data * the byte array * @param lowerCase * the flag if the result shell be transform in lower case. If true the result is * lowercase otherwise uppercase. * @return the resulted char array of the transformation. */ public static char[] encodeHex(final byte[] data, final boolean lowerCase) { return Hex.encodeHex(data, lowerCase); }
From source file:com.axelor.apps.account.ebics.certificate.KeyUtil.java
/** * Returns the digest value of a given public key. * /*from w ww . j a v a 2s . co m*/ * * <p>In Version H003? of the EBICS protocol the ES of the financial: * * <p>The SHA-256 hash values of the financial institution's public keys for X002 and E002 are * composed by concatenating the exponent with a blank character and the modulus in hexadecimal * representation (using lower case letters) without leading zero (as to the hexadecimal * representation). The resulting string has to be converted into a byte array based on US ASCII * code. * * @param publicKey the public key * @return the digest value * @throws EbicsException */ public static byte[] getKeyDigest(RSAPublicKey publicKey) throws AxelorException { String modulus; String exponent; String hash; byte[] digest; exponent = Hex.encodeHexString(publicKey.getPublicExponent().toByteArray()); modulus = Hex.encodeHexString(removeFirstByte(publicKey.getModulus().toByteArray())); hash = exponent + " " + modulus; if (hash.charAt(0) == '0') { hash = hash.substring(1); } try { digest = MessageDigest.getInstance("SHA-256", "BC").digest(hash.getBytes("US-ASCII")); } catch (GeneralSecurityException e) { throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR); } catch (UnsupportedEncodingException e) { throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR); } return new String(Hex.encodeHex(digest, false)).getBytes(); }
From source file:de.alpharogroup.crypto.aes.HexEncryptor.java
/** * Encrypt the given String./*from w ww.j av a 2 s . com*/ * * @param string * The String to encrypt. * @return The encrypted String. * @throws InvalidKeyException * the invalid key exception is thrown if initialization of the cypher object fails. * @throws UnsupportedEncodingException * is thrown by get the byte array of the private key String object fails. * @throws NoSuchAlgorithmException * is thrown if instantiation of the cypher object fails. * @throws NoSuchPaddingException * is thrown if instantiation of the cypher object fails. * @throws IllegalBlockSizeException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @throws BadPaddingException * is thrown if {@link Cipher#doFinal(byte[])} fails. */ @Override public String encrypt(final String string) throws InvalidKeyException, UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { initialize(); final byte[] utf8 = string.getBytes("UTF-8"); final byte[] encrypt = this.cipher.doFinal(utf8); final char[] original = Hex.encodeHex(encrypt, false); return new String(original); }
From source file:net.sourceforge.jaulp.crypto.aes.HexEncryptor.java
/** * Encrypt the given String.// w w w. ja v a 2 s .c o m * * @param string * The String to encrypt. * @return The encrypted String. * @throws InvalidKeyException * the invalid key exception is thrown if initialization of the cypher object fails. * @throws UnsupportedEncodingException * is thrown by get the byte array of the private key String object fails. * @throws NoSuchAlgorithmException * is thrown if instantiation of the cypher object fails. * @throws NoSuchPaddingException * is thrown if instantiation of the cypher object fails. * @throws IllegalBlockSizeException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @throws BadPaddingException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @see net.sourceforge.jaulp.crypto.interfaces.Encryptor#encrypt(java.lang.String) */ @Override public String encrypt(final String string) throws InvalidKeyException, UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { initialize(); final byte[] utf8 = string.getBytes("UTF-8"); final byte[] encrypt = this.cipher.doFinal(utf8); char[] original = Hex.encodeHex(encrypt, false); return new String(original); }
From source file:de.alpharogroup.crypto.key.PublicKeyHexEncryptor.java
/** * Encrypt the given String./* www.ja va 2 s. co m*/ * * @param string * The String to encrypt. * @return The encrypted String. * @throws InvalidKeyException * the invalid key exception is thrown if initialization of the cypher object fails. * @throws NoSuchAlgorithmException * is thrown if instantiation of the cypher object fails. * @throws NoSuchPaddingException * is thrown if instantiation of the cypher object fails. * @throws IllegalBlockSizeException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @throws BadPaddingException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @throws InvalidKeySpecException * is thrown if generation of the SecretKey object fails. * @throws IOException * Signals that an I/O exception has occurred. */ public String encrypt(final String string) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, IOException { initialize(); final byte[] utf8 = string.getBytes("UTF-8"); final byte[] encrypt = this.cipher.doFinal(utf8); final char[] original = Hex.encodeHex(encrypt, false); return new String(original); }
From source file:de.alpharogroup.crypto.aes.HexNewEncryptor.java
/** * Encrypt the given String.// w w w . j av a 2s . c om * * @param string * The String to encrypt. * @return The encrypted String. * @throws InvalidKeyException * the invalid key exception is thrown if initialization of the cypher object fails. * @throws UnsupportedEncodingException * is thrown by get the byte array of the private key String object fails. * @throws NoSuchAlgorithmException * is thrown if instantiation of the cypher object fails. * @throws NoSuchPaddingException * is thrown if instantiation of the cypher object fails. * @throws IllegalBlockSizeException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @throws BadPaddingException * is thrown if {@link Cipher#doFinal(byte[])} fails. * @see de.alpharogroup.crypto.interfaces.Encryptor#encrypt(java.lang.String) */ @Override public String encrypt(final String string) throws InvalidKeyException, UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { final byte[] utf8 = string.getBytes("UTF-8"); final byte[] encrypt = this.cipher.doFinal(utf8); final char[] original = Hex.encodeHex(encrypt, false); return new String(original); }
From source file:me.schiz.jmeter.ring.udp.EventLoopRunnable.java
private void readCallback(DatagramChannel dc) throws IOException { Token t = ring.get(dc);// ww w. j a v a 2s . c o m t.lock.lock(); try { t.remote = dc.receive(byteBuffer); //EOF if (t != null) { if (t.timeout != null) t.timeout.cancel(); } byteBuffer.flip(); if (t.sampleResult != null) { t.sampleResult.sampleEnd(); byte[] res = Charset.defaultCharset().decode(byteBuffer).toString().getBytes(); if (t.ishex) { t.sampleResult.setResponseData(String.valueOf(Hex.encodeHex(res, true)).getBytes()); } else { t.sampleResult.setResponseData(res); } while (!t.queue.offer(t.sampleResult)) { } t.sampleResult = null; t.queue = null; } else { log.warn("have response without request"); } ring.release(t.id); } catch (IOException e) { t.sampleResult.setResponseCode(e.toString()); t.sampleResult.setSuccessful(false); while (!t.queue.offer(t.sampleResult)) { } } finally { t.lock.unlock(); byteBuffer.clear(); } }
From source file:eu.europa.ec.markt.dss.DSSUtils.java
/** * Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned * String will be double the length of the passed array, as it takes two characters to represent any given byte. If * the input array is null then null is returned. The obtained string is converted to uppercase. * * @param value/*from w ww. j ava 2s .co m*/ * @return */ public static String toHex(final byte[] value) { return (value != null) ? new String(Hex.encodeHex(value, false)) : null; }