List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:libepg.epg.section.eit.descriptor.extendedeventdescriptor.ExtendedEventDescriptorTest.java
/** * Test of getText_char method, of class ExtendedEventDescriptor. * ??????/*from w ww. j a v a2 s . co m*/ * * @throws org.apache.commons.codec.DecoderException * @throws java.lang.reflect.InvocationTargetException */ @Test public void testGetText_char2() throws DecoderException, InvocationTargetException { LOG.debug("getText_char2"); byte[] dat = this.descs.getEXTENDED_EVENT_DESCRIPTOR_BYTE(); byte[] dat2 = Hex.decodeHex("0e4e484b451d461d6c310f456c357e".toCharArray()); // byte[] dat3 = ArrayUtils.addAll(dat, dat2); LOG.debug(Hex.encodeHexString(dat)); LOG.debug(Hex.encodeHexString(dat2)); LOG.debug(Hex.encodeHexString(dat3)); //?? dat3[1] = (byte) (dat.length - 1 + dat2.length - 1); //? dat3[dat.length - 1] = (byte) dat2.length; LOG.debug(Hex.encodeHexString(dat3)); Descriptor dummy = Descriptors.init(dat3); ExtendedEventDescriptor instance = new ExtendedEventDescriptor(dummy); byte[] expResult = dat2; byte[] result = instance.getText_char(); assertArrayEquals(expResult, result); }
From source file:libepg.epg.section.eventinformationtable.descriptor.extendedeventdescriptor.ExtendedEventDescriptorTest.java
/** * Test of getText_char method, of class ExtendedEventDescriptor. * ??????//from w w w . j av a 2 s .c o m * * @throws org.apache.commons.codec.DecoderException * @throws java.lang.reflect.InvocationTargetException */ @Test public void testGetText_char2() throws DecoderException, InvocationTargetException { LOG.info("getText_char2"); byte[] dat = this.descs.getEXTENDED_EVENT_DESCRIPTOR_BYTE(); byte[] dat2 = Hex.decodeHex("0e4e484b451d461d6c310f456c357e".toCharArray()); // byte[] dat3 = ArrayUtils.addAll(dat, dat2); LOG.info(Hex.encodeHexString(dat)); LOG.info(Hex.encodeHexString(dat2)); LOG.info(Hex.encodeHexString(dat3)); //?? dat3[1] = (byte) (dat.length - 1 + dat2.length - 1); //? dat3[dat.length - 1] = (byte) dat2.length; LOG.info(Hex.encodeHexString(dat3)); Descriptor dummy = Descriptors.init(dat3); ExtendedEventDescriptor instance = new ExtendedEventDescriptor(dummy); byte[] expResult = dat2; byte[] result = instance.getText_char(); assertArrayEquals(expResult, result); }
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Calculates the MD2 digest and returns the value as a 32 character hex string. * * @param data/*from www .j ava 2 s . c om*/ * Data to digest * @return MD2 digest as a hex string * @since 1.7 */ public static String md2Hex(final byte[] data) { return Hex.encodeHexString(md2(data)); }
From source file:dk.i2m.netbeans.modules.ldapexplorer.ui.ExplorerTopComponent.java
private void addRow(DefaultTableModel model, String att, Object val) { final String LBL_PREFIX = "ATTRIBUTE_FRIENDLY_NAME_"; String attName = att;/* w w w . j av a 2 s . c om*/ if (bundle.containsKey(LBL_PREFIX + att.toLowerCase())) { attName = bundle.getString(LBL_PREFIX + att.toLowerCase()); } if (val instanceof byte[]) { // Field is binary - convert it to hexadecimals model.addRow(new Object[] { attName, att, Hex.encodeHexString((byte[]) val) }); } else { model.addRow(new Object[] { attName, att, val }); } }
From source file:be.fedict.eid.dss.model.bean.TrustValidationServiceBean.java
public void validate(TimeStampToken timeStampToken, List<OCSPResp> ocspResponses, List<X509CRL> crls) throws CertificateEncodingException, TrustDomainNotFoundException, RevocationDataNotFoundException, ValidationFailedException, NoSuchAlgorithmException, NoSuchProviderException, CMSException, CertStoreException, IOException { LOG.debug("performing historical TSA validation..."); String tsaTrustDomain = this.configuration.getValue(ConfigProperty.TSA_TRUST_DOMAIN, String.class); LOG.debug("TSA trust domain: " + tsaTrustDomain); Date validationDate = timeStampToken.getTimeStampInfo().getGenTime(); LOG.debug("TSA validation date is TST time: " + validationDate); LOG.debug("# TSA ocsp responses: " + ocspResponses.size()); LOG.debug("# TSA CRLs: " + crls.size()); /*//from ww w . ja va 2 s . c om *Building TSA chain. (Code from eID-applet) * */ SignerId signerId = timeStampToken.getSID(); BigInteger signerCertSerialNumber = signerId.getSerialNumber(); //X500Principal signerCertIssuer = signerId.getIssuer(); X500Principal signerCertIssuer = new X500Principal(signerId.getIssuer().getEncoded()); LOG.debug("signer cert serial number: " + signerCertSerialNumber); LOG.debug("signer cert issuer: " + signerCertIssuer); // TSP signer certificates retrieval CertStore certStore = timeStampToken.getCertificatesAndCRLs("Collection", BouncyCastleProvider.PROVIDER_NAME); Collection<? extends Certificate> certificates = certStore.getCertificates(null); X509Certificate signerCert = null; Map<String, X509Certificate> certificateMap = new HashMap<String, X509Certificate>(); for (Certificate certificate : certificates) { X509Certificate x509Certificate = (X509Certificate) certificate; if (signerCertIssuer.equals(x509Certificate.getIssuerX500Principal()) && signerCertSerialNumber.equals(x509Certificate.getSerialNumber())) { signerCert = x509Certificate; } String ski = Hex.encodeHexString(getSubjectKeyId(x509Certificate)); certificateMap.put(ski, x509Certificate); LOG.debug("embedded certificate: " + x509Certificate.getSubjectX500Principal() + "; SKI=" + ski); } // TSP signer cert path building if (null == signerCert) { throw new RuntimeException("TSP response token has no signer certificate"); } List<X509Certificate> tspCertificateChain = new LinkedList<X509Certificate>(); X509Certificate tsaIssuer = loadCertificate( "be/fedict/eid/dss/CA POLITICA SELLADO DE TIEMPO - COSTA RICA.crt"); X509Certificate rootCA = loadCertificate("be/fedict/eid/dss/CA RAIZ NACIONAL COSTA RICA.cer"); LOG.debug("adding to certificate chain: " + signerCert.getSubjectX500Principal()); tspCertificateChain.add(signerCert); LOG.debug("adding to certificate chain: " + tsaIssuer.getSubjectX500Principal()); tspCertificateChain.add(tsaIssuer); LOG.debug("adding to certificate chain: " + rootCA.getSubjectX500Principal()); tspCertificateChain.add(rootCA); /* * Perform PKI validation via eID Trust Service. */ getXkms2Client().validate(tsaTrustDomain, tspCertificateChain, validationDate, ocspResponses, crls); }
From source file:eu.europa.ec.markt.dss.signature.cades.CAdESProfileC.java
/** * Create a reference on a OCSPResp/* w w w . j a v a 2 s. c om*/ * * @param ocspResp * @return * @throws NoSuchAlgorithmException * @throws OCSPException * @throws IOException */ private OcspResponsesID makeOcspResponsesID(BasicOCSPResp ocspResp) throws NoSuchAlgorithmException, OCSPException, IOException { /* * We hash the complete response, this is not clear in the TS but the issue was addressed here: * http://lists.iaik.tugraz.at/pipermail/jce-general/2007-January/005914.html */ MessageDigest sha1digest = MessageDigest.getInstance(X509ObjectIdentifiers.id_SHA1.getId(), new BouncyCastleProvider()); byte[] digestValue = sha1digest.digest(ocspResp.getEncoded()); OtherHash hash = new OtherHash(digestValue); OcspResponsesID ocsprespid = new OcspResponsesID(new OcspIdentifier( ocspResp.getResponderId().toASN1Object(), new DERGeneralizedTime(ocspResp.getProducedAt())), hash); LOG.info("Incorporate OcspResponseId[hash=" + Hex.encodeHexString(digestValue) + ",producedAt=" + ocspResp.getProducedAt()); return ocsprespid; }
From source file:edu.wpi.checksims.algorithm.linesimilarity.LineSimilarityChecker.java
void addLinesToMap(TokenList lines, Map<String, List<SubmissionLine>> lineDatabase, Submission submitter, MessageDigest hasher) {/*from ww w . j a v a 2s.c o m*/ for (int i = 0; i < lines.size(); i++) { Token token = lines.get(i); String hash = Hex.encodeHexString(hasher.digest(token.getTokenAsString().getBytes())); if (lineDatabase.get(hash) == null) { lineDatabase.put(hash, new ArrayList<>()); } SubmissionLine line = new SubmissionLine(i, submitter); lineDatabase.get(hash).add(line); } }
From source file:libepg.epg.section.sectionreconstructor.SectionReconstructor.java
/** * ??????? ??????????????????// www. j ava 2s. co m * * @return ??? * */ public synchronized Set<byte[]> getSectionByteArrays() { Set<byte[]> ret = new TreeSet<>((byte[] left, byte[] right) -> { for (int i = 0, j = 0; i < left.length && j < right.length; i++, j++) { int a = (left[i] & 0xff); int b = (right[j] & 0xff); if (a != b) { return a - b; } } return left.length - right.length; }); boolean first_start_indicator_found = false; ByteBuffer buf = null; PayLoadSplitter splitter = new PayLoadSplitter(); for (TsPacketParcel parcel : parcels) { splitter.setPacket(parcel.getPacket()); Map<PayLoadSplitter.PAYLOAD_PART_KEY, byte[]> t_map = splitter.getSplittedPayLoad(); if ((buf == null) || (parcel.isMissingJustBefore() == TsPacketParcel.MISSING_PACKET_FLAG.MISSING_JUST_BEFORE)) { if (LOG.isTraceEnabled()) { LOG.trace( "?????????????????????????"); } if (buf == null) { buf = ByteBuffer.allocate(TABLE_ID.MAX_SECTION_LENGTH.BYTE_4093.getMaxSectionLength()); } else { buf.clear(); } } if (LOG.isTraceEnabled()) { LOG.trace("?=" + Hex.encodeHexString(buf.array())); } if ((first_start_indicator_found == false) && (parcel.getPacket() .getPayload_unit_start_indicator() == TsPacket.PAYLOAD_UNIT_START_INDICATOR.START_PES_OR_START_SECTION)) { if (LOG.isTraceEnabled()) { LOG.trace("??"); } first_start_indicator_found = true; } if (first_start_indicator_found == false) { if (LOG.isTraceEnabled()) { LOG.trace( "?????????"); } } else if (parcel.getPacket() .getPayload_unit_start_indicator() == TsPacket.PAYLOAD_UNIT_START_INDICATOR.START_PES_OR_START_SECTION) { if (LOG.isTraceEnabled()) { LOG.trace( "??????????"); } if (buf.position() == 0) { if (LOG.isTraceEnabled()) { LOG.trace( "??0=?????????->??2?????????????+1?????"); } byte[] temp_array = null; if (t_map.size() == 1) { temp_array = t_map.get(PayLoadSplitter.PAYLOAD_PART_KEY.PAYLOAD_AFTER_2_BYTE); } else { temp_array = t_map.get(PayLoadSplitter.PAYLOAD_PART_KEY.NEXT_POINTER); } buf.put(temp_array); } else { if (LOG.isTraceEnabled()) { LOG.trace( "??0????=???????->??2???????????\n???????????????+1?????"); } byte[] temp_array = null; if (t_map.containsKey(PayLoadSplitter.PAYLOAD_PART_KEY.PAYLOAD_AFTER_2_BYTE)) { if (LOG.isTraceEnabled()) { LOG.trace( "???????????????"); } this.addToReturnObject(buf, ret); buf.clear(); temp_array = t_map.get(PayLoadSplitter.PAYLOAD_PART_KEY.PAYLOAD_AFTER_2_BYTE); buf.put(temp_array); } else { if (LOG.isTraceEnabled()) { LOG.trace( "??????????????????"); } temp_array = t_map.get(PayLoadSplitter.PAYLOAD_PART_KEY.PREV_POINTER); buf.put(temp_array); this.addToReturnObject(buf, ret); buf.clear(); temp_array = t_map.get(PayLoadSplitter.PAYLOAD_PART_KEY.NEXT_POINTER); buf.put(temp_array); } } } else { if (LOG.isTraceEnabled()) { LOG.trace( "?????->????->??????"); } buf.put(t_map.get(PayLoadSplitter.PAYLOAD_PART_KEY.ALL_PAYLOAD)); } } return Collections.unmodifiableSet(ret); }
From source file:de.brendamour.jpasskit.signing.PKFileBasedSigningUtil.java
private void hashFilesInDirectory(final File[] files, final Map<String, String> fileWithHashMap, final HashFunction hashFunction, final String parentName) throws PKSigningException { StringBuilder name;//from ww w . j a v a 2 s .c o m HashCode hash; for (File passResourceFile : files) { name = new StringBuilder(); if (passResourceFile.isFile()) { try { hash = Files.hash(passResourceFile, hashFunction); } catch (IOException e) { throw new PKSigningException("Error when hashing files", e); } if (StringUtils.isEmpty(parentName)) { // direct call name.append(passResourceFile.getName()); } else { // recursive call (apeending parent directory) name.append(parentName); name.append(FILE_SEPARATOR_UNIX); name.append(passResourceFile.getName()); } fileWithHashMap.put(name.toString(), Hex.encodeHexString(hash.asBytes())); } else if (passResourceFile.isDirectory()) { if (StringUtils.isEmpty(parentName)) { // direct call name.append(passResourceFile.getName()); } else { // recursive call (apeending parent directory) name.append(parentName); name.append(FILE_SEPARATOR_UNIX); name.append(passResourceFile.getName()); } hashFilesInDirectory(passResourceFile.listFiles(), fileWithHashMap, hashFunction, name.toString()); } } }
From source file:com.exalttech.trex.util.PacketUtil.java
/** * Read pcap file to get all includes packet * * @param pcapFile//from www . j a v a2 s .co m * @return * @throws PcapNativeException * @throws NotOpenException */ private List<String> getpcapPacketList(String pcapFile) throws PcapNativeException, NotOpenException { PcapHandle handler = Pcaps.openOffline(pcapFile); Packet packet = null; List<String> packetList = new ArrayList<>(); while ((packet = handler.getNextPacket()) != null) { packetList.add(Hex.encodeHexString(packet.getRawData())); } return packetList; }