List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:eu.europa.ec.markt.dss.validation.OCSPRef.java
/** * /*from w w w .jav a 2 s .c o m*/ * @param ocspResp * @return */ public boolean match(BasicOCSPResp ocspResp) { try { MessageDigest digest = MessageDigest.getInstance(algorithm); if (matchOnlyBasicOCSPResponse) { digest.update(ocspResp.getEncoded()); } else { digest.update(OCSPUtils.fromBasicToResp(ocspResp).getEncoded()); } byte[] computedValue = digest.digest(); LOG.info("Compare " + Hex.encodeHexString(digestValue) + " to computed value " + Hex.encodeHexString(computedValue) + " of BasicOCSPResp produced at " + ocspResp.getProducedAt()); return Arrays.equals(digestValue, computedValue); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("Maybe BouncyCastle provider is not installed ?", ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:com.liferay.portal.util.DigesterImpl.java
public String digestHex(String algorithm, ByteBuffer byteBuffer) { byte[] bytes = digestRaw(algorithm, byteBuffer); return Hex.encodeHexString(bytes); }
From source file:com.netcrest.pado.internal.security.AESCipher.java
public static String encryptUserTextToHex(String clearText) throws Exception { byte[] buf = encryptUserTextToBinary(clearText); String hexEncrypted = Hex.encodeHexString(buf); return hexEncrypted.toUpperCase(); }
From source file:ch.cyberduck.core.irods.IRODSListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try {//from ww w.j a v a 2 s. co m final AttributedList<Path> children = new AttributedList<Path>(); final IRODSFileSystemAO fs = session.getClient(); final IRODSFile f = fs.getIRODSFileFactory().instanceIRODSFile(directory.getAbsolute()); if (!f.exists()) { throw new NotfoundException(directory.getAbsolute()); } for (File file : fs.getListInDirWithFileFilter(f, TrueFileFilter.TRUE)) { final String normalized = PathNormalizer.normalize(file.getAbsolutePath(), true); if (StringUtils.equals(normalized, directory.getAbsolute())) { continue; } final PathAttributes attributes = new PathAttributes(); final ObjStat stats = fs.getObjStat(file.getAbsolutePath()); attributes.setModificationDate(stats.getModifiedAt().getTime()); attributes.setCreationDate(stats.getCreatedAt().getTime()); attributes.setSize(stats.getObjSize()); attributes .setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(stats.getChecksum())))); attributes.setOwner(stats.getOwnerName()); attributes.setGroup(stats.getOwnerZone()); children.add(new Path(directory, PathNormalizer.name(normalized), file.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attributes)); listener.chunk(directory, children); } return children; } catch (JargonException e) { throw new IRODSExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
From source file:com.linkedin.databus2.tools.dtail.EventInfoDtailPrinter.java
/** * @see com.linkedin.databus2.tools.dtail.DtailPrinter#printEvent(com.linkedin.databus.core.DbusEventInternalReadable, com.linkedin.databus.client.pub.DbusEventDecoder) *//*from w w w .j a va 2 s . co m*/ @Override public ConsumerCallbackResult printEvent(DbusEventInternalReadable e, DbusEventDecoder eventDecoder) { DbusEventAvroDecoder avroDecoder = (DbusEventAvroDecoder) eventDecoder; byte[] payloadSchemaDigest = e.schemaId(); DbusEventPart metadataPart = e.getPayloadMetadataPart(); String s = String.format( "format=%s opcode=%s partition=%d scn=%d ts=%d (%s.%d) srcid=%d extRepl=%s schema=%s " + "payload_schema_digest=%s metadata_schema=%s metadata_schema_digest=%s", e.getClass().getSimpleName(), e.getOpcode(), e.getPartitionId(), e.sequence(), e.timestampInNanos(), EVENT_TS_FORMAT.format(new Date(e.timestampInNanos() / 1000000)), e.timestampInNanos() % 1000000000, e.getSourceId(), e.isExtReplicatedEvent(), versionedSchemaId(eventDecoder.getPayloadSchema(e)), null != payloadSchemaDigest ? Hex.encodeHexString(payloadSchemaDigest) : "null", null != metadataPart ? versionedSchemaId(avroDecoder.getMetadataSchema(e)) : "null", null != metadataPart ? Hex.encodeHexString(metadataPart.getSchemaDigest()) : "null"); try { _out.write(s.getBytes("UTF-8")); _out.write('\n'); } catch (UnsupportedEncodingException e1) { return ConsumerCallbackResult.ERROR; } catch (IOException e1) { return ConsumerCallbackResult.ERROR; } return ConsumerCallbackResult.SUCCESS; }
From source file:libepg.util.bytearray.ByteArraySplitter.java
/** * ????????????????????0??<br>//from ww w .jav a 2s. c o m * 1.??????????????????<br> * 2.??????????????????????????<br> * * * @author normal * @param src ? * @param lengthFieldPosition * ??(??????????????)<br> * @param lengthFieldLength ????? * @param preProcessor ???8????????????? * @return ??? * * ????<br> * X=?????<br> * Y=?<br> * Z=????<br> * ???=XXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZZ<br> * ???1=XXXXYYZZZZZZ<br> * ???2=XXXXYYZZZZZZ<br> * ???3=XXXXYYZZZZZZ<br> * ???4=XXXXYYZZZZZZ<br> * ???5=XXXXYYZZZZZZ<br> * ???6=XXXXYYZZZZZZ<br> * ???7=XXXXYYZZZZZZ<br> * ???8=XXXXYYZZZZZZ<br> * ???9=XXXXYYZZZZZZZ<br> */ public static synchronized List<byte[]> splitByLengthField(byte[] src, int lengthFieldPosition, int lengthFieldLength, UnaryOperator<Integer> preProcessor) { UnaryOperator<Integer> preProcessor_t; if (preProcessor == null) { throw new NullPointerException("??????????"); } else { preProcessor_t = preProcessor; } if (LOG.isTraceEnabled()) { LOG.trace(" = " + Hex.encodeHexString(src)); LOG.trace("?? = " + lengthFieldPosition); LOG.trace("??? = " + lengthFieldLength); } List<byte[]> dest = new ArrayList<>(); try (ByteArrayInputStream bis = new ByteArrayInputStream(src)) { while (bis.available() > 0) { //?????????????????? bis.mark(0); //??????????????????????? bis.skip(lengthFieldPosition - 1); //?? byte[] lengthFieldValue_Byte = new byte[lengthFieldLength]; if (bis.read(lengthFieldValue_Byte) == -1) { break; } int lengthFieldValue = ByteConverter.bytesToInt(lengthFieldValue_Byte);//? int lengthFieldValue_Processed = preProcessor_t.apply(lengthFieldValue); if (LOG.isTraceEnabled()) { LOG.trace("?(byte) = " + Hex.encodeHexString(lengthFieldValue_Byte)); LOG.trace("?(?) = " + lengthFieldValue); LOG.trace("?() = " + lengthFieldValue_Processed); } //?? bis.reset(); //???????(??????-1+???+??) int partLength = lengthFieldPosition - 1 + lengthFieldLength + lengthFieldValue_Processed; if (LOG.isTraceEnabled()) { LOG.trace("?????= " + partLength); } //??? byte[] temp = new byte[partLength]; //? if (bis.read(temp) == -1) { break; } if (LOG.isTraceEnabled()) { LOG.trace("?= " + Hex.encodeHexString(temp)); } dest.add(temp); } } catch (IOException ex) { LOG.info("???????????"); } finally { return dest; } }
From source file:be.fedict.eid.applet.service.signer.SHA1WithRSAProxySignature.java
@Override protected byte[] engineSign() throws SignatureException { LOG.debug("engineSign"); byte[] signatureValue = SHA1WithRSAProxySignature.signatureValues.get(); if (null != signatureValue) { LOG.debug("injecting signature value: " + Hex.encodeHexString(signatureValue)); reset();//from w w w . j a v a 2s . c o m return signatureValue; } LOG.debug("returning a dummy signature value"); return "dummy".getBytes(); }
From source file:com.emc.ecs.sync.CasMigrationTest.java
@Test public void testPipedStreams() throws Exception { Random random = new Random(); // test smaller than pipe buffer byte[] source = new byte[random.nextInt(BUFFER_SIZE) + 1]; random.nextBytes(source);/*from w ww . jav a 2 s .c o m*/ String md5 = Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(source)); Assert.assertEquals("MD5 mismatch", md5, pipeAndGetMd5(source)); // test larger than pipe buffer source = new byte[random.nextInt(BUFFER_SIZE) + BUFFER_SIZE + 1]; random.nextBytes(source); md5 = Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(source)); Assert.assertEquals("MD5 mismatch", md5, pipeAndGetMd5(source)); }
From source file:com.zimbra.cs.store.triton.TritonIncomingBlob.java
@Override public Blob getBlob() throws IOException, ServiceException { if (outStream != null) { outStream.close();/* w w w . jav a 2 s.com*/ } String locator = Hex.encodeHexString((digest.digest())); return new TritonBlob(blobBuilder.finish(), locator, uploadUrl.toString(), serverToken); }
From source file:inti.ws.spring.resource.FilteredWebResource.java
@Override public void update() throws Exception { ExpressionFactory factory;/*from ww w .j a v a2 s . c o m*/ ValueExpression var; Object val; StringBuilder builder = new StringBuilder(32); MessageDigest digest = DIGESTS.get(); for (WebResource dependency : dependencies) { dependency.updateIfNeeded(); } super.update(); factory = ExpressionFactory.newInstance(); content = factory.createValueExpression(context, compressedFile, String.class); for (Map.Entry<String, Object> parameter : parameters.entrySet()) { var = factory.createValueExpression(context, "${" + parameter.getKey() + '}', String.class); val = parameter.getValue(); if (val instanceof WebResource) { ((WebResource) val).updateIfNeeded(); val = ((WebResource) val).getContent().hashCode(); } var.setValue(context, val); } compressedFile = (String) content.getValue(context); digest.reset(); builder.append(Hex.encodeHexString(digest.digest(compressedFile.getBytes(StandardCharsets.UTF_8)))); messageDigest = builder.toString(); builder.delete(0, builder.length()); DATE_FORMATTER.formatDate(lastModified, builder); lastModifiedString = builder.toString(); }