List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.cedarsoft.serialization.jackson.test.UserSerializerTest.java
@DataPoint public static Entry<?> json() { return create( new User("Max Mustermann", Arrays.asList(new Email("test@test.de"), new Email("other@test.de")), Arrays.asList(new Role(1, "Nobody"), new Role(0, "Admin")), new Email("single"), new UserDetails(2351351L, 36351531153L, new String(Hex.encodeHex("hash".getBytes())).getBytes())), UserSerializerTest.class.getResource("user.withDetails.json")); }
From source file:com.thruzero.common.core.security.MessageDigestHelper.java
/** MD5 encode the given plaintext byte array. */ public String encodeAsMd5Hex(final byte[] plaintext) { String result = null;//ww w . j ava2s . c o m MessageDigest md5 = getMd5(); if (md5 != null) { result = new String(Hex.encodeHex(md5.digest(plaintext))); } return result; }
From source file:com.aqnote.shared.encrypt.util.DesUtil.java
public synchronized static String encrypt(String plaintext) { String result = null;/* ww w .j a v a 2 s. c om*/ try { if (plaintext == null) { return null; } result = new String(Hex.encodeHex(encodeCipher.doFinal(plaintext.getBytes(ENCODE_UTF_8)))); } catch (IllegalStateException e) { logger.error(MSG(R.F, "encrypt", plaintext, e.getMessage()), e); } catch (IllegalBlockSizeException e) { logger.error(MSG(R.F, "encrypt", plaintext, e.getMessage()), e); } catch (BadPaddingException e) { logger.error(MSG(R.F, "encrypt", plaintext, e.getMessage()), e); } catch (UnsupportedEncodingException e) { logger.error(MSG(R.F, "encrypt", plaintext, e.getMessage()), e); } finally { } return result; }
From source file:com.haulmont.cuba.web.test.PasswordEncryptionTest.java
protected String encryptPassword(String password) { SecretKeySpec key = new SecretKeySpec(PASSWORD_KEY.getBytes(), "DES"); IvParameterSpec ivSpec = new IvParameterSpec(PASSWORD_KEY.getBytes()); String result;/*w w w . ja v a 2 s . com*/ try { Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); result = new String(Hex.encodeHex(cipher.doFinal(password.getBytes()))); } catch (Exception e) { throw new RuntimeException(e); } return result; }
From source file:data.repository.pragma.utils.MD5Utils.java
public static String getDigest(InputStream is, MessageDigest md, int byteArraySize) { md.reset();/*ww w.ja v a 2s. c o m*/ byte[] bytes = new byte[byteArraySize]; int numBytes; try { while ((numBytes = is.read(bytes)) != -1) { md.update(bytes, 0, numBytes); } byte[] digest = md.digest(); String result = new String(Hex.encodeHex(digest)); return result; } catch (IOException e) { // TODO Auto-generated catch block return null; } }
From source file:mitm.common.util.HexUtils.java
public static String hexEncode(byte[] data, String defaultIfNull) { if (data == null) { return defaultIfNull; }/*from w w w. java 2s . co m*/ return String.copyValueOf(Hex.encodeHex(data)).toUpperCase(); }
From source file:com.amazonaws.cognito.devauthsample.Utilities.java
public static String sign(String content, String key) { try {// www . ja v a2 s . c om byte[] data = content.getBytes(ENCODING_FORMAT); Mac mac = Mac.getInstance(SIGNATURE_METHOD); mac.init(new SecretKeySpec(key.getBytes(ENCODING_FORMAT), SIGNATURE_METHOD)); char[] signature = Hex.encodeHex(mac.doFinal(data)); return new String(signature); } catch (Exception e) { log.log(Level.SEVERE, "Exception during sign", e); } return null; }
From source file:com.cisco.oss.foundation.http.server.TraceWrapper.java
public static String toStringWithBody(String data, String ndsBodyStatusHeader, byte[] body, int bodyLimit, String contentType, List<String> contentTypes, String characterEncoding, String bodySuffix, boolean forceBinaryPrint) { int dataLength = data.length(); final StringBuilder builder = new StringBuilder(dataLength + bodyLimit); builder.append(data);/* w w w. j ava2 s . c o m*/ builder.append("\n"); boolean isText = false; if (body.length > 0) { boolean bodyEncrypted = (ndsBodyStatusHeader != null) && (ndsBodyStatusHeader.equalsIgnoreCase("Encrypted")); if (!forceBinaryPrint && !bodyEncrypted && contentType != null) { for (String type : contentTypes) { if (contentType.toLowerCase().contains(type)) { String enc = characterEncoding; if (enc == null) { enc = "UTF-8"; } try { builder.append(new String(body, enc)); isText = true; break; } catch (UnsupportedEncodingException e) { LOGGER.trace("problem appending string body with {} encoding. error is: {}", enc, e); break; } } } } if (!isText) { builder.append(Hex.encodeHex(body)); } if (builder.length() > dataLength + bodyLimit) { builder.setLength(dataLength + bodyLimit); builder.replace(builder.length() - bodySuffix.length(), builder.length(), bodySuffix); } } return builder.toString(); }
From source file:com.lightboxtechnologies.spectrum.FsEntryRowFilter.java
@Override public void readFields(DataInput in) throws IOException { super.readFields(in); LOG.info("Read in image ID " + new String(Hex.encodeHex(getValue()))); }
From source file:client.Client.java
static String toHex(String input) { return new String(Hex.encodeHex(input.getBytes())); }