List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:controllers.DiscourseAuth.java
private static String checksum(SecretKeySpec key, String macData) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException { Mac mac = Mac.getInstance("HmacSHA256"); mac.init(key);//from w w w .java 2 s . c o m byte[] doFinal = mac.doFinal(macData.getBytes(StandardCharsets.UTF_8)); return Hex.encodeHexString(doFinal); }
From source file:com.cedarsoft.serialization.test.performance.Bson4JacksonTest.java
@Test public void testMapper() throws Exception { ObjectMapper mapper = new ObjectMapper(jsonFactory); com.cedarsoft.serialization.test.performance.jaxb.FileType fileType = new com.cedarsoft.serialization.test.performance.jaxb.FileType( "Canon Raw", new com.cedarsoft.serialization.test.performance.jaxb.Extension(".", "cr2", true), false);//from ww w .j a va 2s .co m ByteArrayOutputStream out = new ByteArrayOutputStream(); mapper.writeValue(out, fileType); Assertions.assertThat(Hex.encodeHexString(out.toByteArray())).describedAs(out.toString()).isEqualTo( "0000000008646570656e64656e740000026964000a00000043616e6f6e205261770003657874656e73696f6e00000000000264656c696d6974657200020000002e0002657874656e73696f6e0004000000637232000864656661756c7400010000"); }
From source file:com.springcryptoutils.core.digest.DigesterImpl.java
/** * Returns the message digest. The representation of the message digest * depends on the outputMode property./*from ww w.ja v a 2 s . com*/ * * @param message the message * @return the message digest * @see #setOutputMode(OutputMode) */ public String digest(String message) { final byte[] messageAsByteArray; try { messageAsByteArray = message.getBytes(charsetName); } catch (UnsupportedEncodingException e) { throw new DigestException("error converting message to byte array: charsetName=" + charsetName, e); } final byte[] digest = digest(messageAsByteArray); switch (outputMode) { case BASE64: return Base64.encodeBase64String(digest); case HEX: return Hex.encodeHexString(digest); default: return null; } }
From source file:com.envirover.rockblock.RockBlockClient.java
/** * Sends MAVLink packet to RockBLOCK./* w w w . j a va 2s.c om*/ * * @param packet MAVLink packet to send. */ public void sendMessage(MAVLinkPacket packet) throws ClientProtocolException, IOException { if (packet == null) return; HttpPost httppost = new HttpPost(serviceURL); String data = Hex.encodeHexString(packet.encodePacket()); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair(PARAM_IMEI, imei)); params.add(new BasicNameValuePair(PARAM_USERNAME, username)); params.add(new BasicNameValuePair(PARAM_PASSWORD, password)); params.add(new BasicNameValuePair(PARAM_DATA, data)); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); String responseString = null; if (entity != null) { InputStream responseStream = entity.getContent(); try { responseString = IOUtils.toString(responseStream); } finally { responseStream.close(); } } if (responseString == null || responseString.startsWith("FAILED")) { throw new IOException(String.format("Failed to post message to RockBLOCK API. %s", responseString)); } MAVLinkLogger.log(Level.INFO, "MT", packet); }
From source file:com.redhat.victims.VictimsResultCache.java
/** * The hashing function used by the Cache. * //from ww w . java 2s .co m * @param key * @return * @throws VictimsException */ protected String hash(String key) throws VictimsException { try { MessageDigest mda = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_256); return Hex.encodeHexString(mda.digest(key.getBytes())); } catch (NoSuchAlgorithmException e) { throw new VictimsException(String.format("Could not hash key: %s", key), e); } }
From source file:ch.rgw.tools.PasswordEncryptionService.java
public String getEncryptedPasswordAsHexString(String password, String salt) throws NoSuchAlgorithmException, InvalidKeySpecException, DecoderException { byte[] encryptedPassword = getEncryptedPassword(password, Hex.decodeHex(salt.toCharArray())); return Hex.encodeHexString(encryptedPassword); }
From source file:com.jfinal.ext.kit.ModelFingerprint.java
public String calcFingerprint() { if (fingerprint == null) { StringBuilder sb = new StringBuilder(); for (String col : fingerprintColumns()) { sb.append(get(col));/*from w w w.jav a2 s. c om*/ sb.append("|"); } sb.deleteCharAt(sb.length() - 1); try { MessageDigest md = MessageDigest.getInstance("MD5"); fingerprint = Hex.encodeHexString(md.digest(sb.toString().getBytes())); } catch (Exception e) { fingerprint = "" + hashCode(); } } return fingerprint; }
From source file:com.shuffle.p2p.Bytestring.java
@Override public String toString() { return "Bytestring[" + Hex.encodeHexString(bytes) + "]"; }
From source file:be.fedict.trust.service.bean.CertificateAuthorityLookupBean.java
private void refreshLookupMap() throws CertificateEncodingException, NoSuchAlgorithmException { LOG.debug("refreshing lookup map"); List<CertificateAuthorityEntity> activeCertificateAuthorities = this.certificateAuthorityDAO .listActiveCertificateAuthorities(); Map<String, String> freshLookupMap = new HashMap<String, String>(); for (CertificateAuthorityEntity certificateAuthority : activeCertificateAuthorities) { X509Certificate caCert = certificateAuthority.getCertificate(); X509Principal issuerName = PrincipalUtil.getSubjectX509Principal(caCert); byte[] issuerNameHash = getHash(issuerName.getEncoded()); String caNameHashKey = Hex.encodeHexString(issuerNameHash); String caName = caCert.getSubjectX500Principal().toString(); freshLookupMap.put(caNameHashKey, caName); LOG.debug("lookup entry: " + caNameHashKey + " = " + caName); }/*ww w . ja va 2 s. com*/ this.lookupMap = freshLookupMap; // concurrency is no problem here }
From source file:com.github.nlloyd.hornofmongo.adaptor.BinData.java
@JSFunction public String hex() { String hexStr = Hex.encodeHexString(Base64.decodeBase64(this.data)); return hexStr; }