Java Code Examples for javax.xml.bind.DatatypeConverter#printHexBinary()
The following examples show how to use
javax.xml.bind.DatatypeConverter#printHexBinary() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RFXComUndecodedRFMessage.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override public State convertToState(RFXComValueSelector valueSelector) throws RFXComException { org.openhab.core.types.State state = UnDefType.UNDEF; if (valueSelector.getItemClass() == StringItem.class) { if (valueSelector == RFXComValueSelector.RAW_DATA) { state = new StringType(DatatypeConverter.printHexBinary(rawMessage)); } else if (valueSelector == RFXComValueSelector.DATA) { state = new StringType(DatatypeConverter.printHexBinary(rawData)); } else { throw new RFXComException("Can't convert " + valueSelector + " to StringItem"); } } else { throw new RFXComException("Can't convert " + valueSelector + " to " + valueSelector.getItemClass()); } return state; }
Example 2
Source File: Utils.java From Skype4J with Apache License 2.0 | 5 votes |
private static String o(String e) { try { byte[] n = e.getBytes(StandardCharsets.UTF_8); MessageDigest mDigest = MessageDigest.getInstance("SHA-256"); byte[] r = mDigest.digest(n); return DatatypeConverter.printHexBinary(r); } catch (NoSuchAlgorithmException e1) { throw new RuntimeException(e1); } }
Example 3
Source File: GatewayApplicationTests.java From mini-platform with MIT License | 5 votes |
@Test public void encodingPBKDF2() { //加密时使用 //salt必填,且需要为十六进制字符串 String salt = DatatypeConverter.printHexBinary("hayden".getBytes()); String hashPassword = getPBKDF2("12345", salt); log.info("PBKDF2 HashPassword: {} , saltSecureRandom: {}", hashPassword, salt); }
Example 4
Source File: PasswordPBKDF2.java From mini-platform with MIT License | 5 votes |
/** * PBKDF2 * @param password * @param salt * @return */ private String getPbkdf2(String password, String salt) { try { byte[] bytes = DatatypeConverter.parseHexBinary(salt); KeySpec spec = new PBEKeySpec(password.toCharArray(), bytes, iterationCount, keyLength); SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(algorithm); byte[] hash = secretKeyFactory.generateSecret(spec).getEncoded(); return DatatypeConverter.printHexBinary(hash); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { return ""; } }
Example 5
Source File: FixedPcapFilter.java From metron with Apache License 2.0 | 5 votes |
@Override public boolean test(PacketInfo pi) { Map<String, Object> fields = packetToFields(pi); VariableResolver resolver = new MapVariableResolver(fields); String srcAddrIn = (String) resolver.resolve(Constants.Fields.SRC_ADDR.getName()); Integer srcPortIn = (Integer) resolver.resolve(Constants.Fields.SRC_PORT.getName()); String dstAddrIn = (String) resolver.resolve(Constants.Fields.DST_ADDR.getName()); Integer dstPortIn = (Integer) resolver.resolve(Constants.Fields.DST_PORT.getName()); String protocolIn = "" + resolver.resolve(Constants.Fields.PROTOCOL.getName()); if(!doHeaderFiltering || testHeader(srcAddrIn, srcPortIn, dstAddrIn, dstPortIn, protocolIn)) { //if we don't do header filtering *or* if we have tested the header and decided it's a match if(packetFilter != null) { //and we have a packet filter, then we need to filter the packet byte[] data = (byte[])resolver.resolve(PcapHelper.PacketFields.PACKET_DATA.getName()); try { return ByteArrayMatchingUtil.INSTANCE.match(packetFilter, data); } catch (ExecutionException e) { throw new IllegalStateException("Unable to perform binary filter: " + packetFilter + " on " + DatatypeConverter.printHexBinary(data), e); } } else if(!doHeaderFiltering){ //otherwise we aren't doing packet filtering either, so we aren't doing any filtering, then we should //pass the test return true; } else { //and if we *are* doing header filtering and not packet filtering, then we want to pass the test return true; } } else { //in this case we're doing header filtering and we failed the header filter test. return false; } }
Example 6
Source File: BitmexWebsocketClient.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
@Override public String getApiSignature(String apiKey, long nonce) { String keyString = "GET" + "/realtime" + nonce; try { Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(apiKey.getBytes("UTF-8"), "HmacSHA256"); sha256_HMAC.init(secret_key); String hash = DatatypeConverter.printHexBinary(sha256_HMAC.doFinal(keyString.getBytes())); return hash; } catch (Exception e) { throw new SumZeroException(e); } }
Example 7
Source File: BitmexSignatureGenerator.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
@Override public String generateSignature(String apiKey, String verb, String path, int expires, String data) { String keyString = verb + path + expires + data; try { Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(apiKey.getBytes("UTF-8"), "HmacSHA256"); sha256_HMAC.init(secret_key); String hash = DatatypeConverter.printHexBinary(sha256_HMAC.doFinal(keyString.getBytes())); return hash; } catch (Exception e) { throw new SumZeroException(e); } }
Example 8
Source File: HexConverter.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Override public String convertToString(byte[] array, Locale locale) { if(array==null || array.length==0) return null; if(maxLength>0 && maxLength<array.length) { byte[] newArray = new byte[maxLength]; System.arraycopy(array, 0, newArray, 0, newArray.length); array = newArray; } String data = DatatypeConverter.printHexBinary(array); if(!Strings.isEmpty(prefix))data = prefix+data; if(cols>0) data = data.replaceAll("(.{"+cols+"})", "$1\n"); return data; }
Example 9
Source File: ProtoUtils.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
public static Common.ChannelHeader createChannelHeader(Common.HeaderType type, String txID, String channelID, long epoch, Timestamp timeStamp, ProposalPackage.ChaincodeHeaderExtension chaincodeHeaderExtension, byte[] tlsCertHash) { if (isDebugLevel) { String tlschs = ""; if (tlsCertHash != null) { tlschs = DatatypeConverter.printHexBinary(tlsCertHash); } logger.debug(format("ChannelHeader: type: %s, version: 1, Txid: %s, channelId: %s, epoch %d, clientTLSCertificate digest: %s", type.name(), txID, channelID, epoch, tlschs)); } Common.ChannelHeader.Builder ret = Common.ChannelHeader.newBuilder() .setType(type.getNumber()) .setVersion(1) .setTxId(txID) .setChannelId(channelID) .setTimestamp(timeStamp) .setEpoch(epoch); if (null != chaincodeHeaderExtension) { ret.setExtension(chaincodeHeaderExtension.toByteString()); } if (tlsCertHash != null) { ret.setTlsCertHash(ByteString.copyFrom(tlsCertHash)); } return ret.build(); }
Example 10
Source File: NioFileCopierWithProgressMeter.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected void calculateChecksumFromMessageDigest() { if ( messageDigest != null ) { checksum = DatatypeConverter.printHexBinary(messageDigest.digest()); } }
Example 11
Source File: SS7Firewall.java From SigFW with GNU Affero General Public License v3.0 | 4 votes |
/** * Method to execute firewall policy on target SCCP message. * * @param mup M3UA instance in forward direction * @param mupReturn M3UA instance in reverse direction, to return UDTS * @param opc M3UA OPC * @param dpc M3UA DPC * @param sls M3UA SLS * @param ni M3UA NI * @param lmrt LongMessageRuleType * @param message Original SCCP message * @param reason the reason of discarding the message * @param lua_hm the LUA parameters, decoded from the message */ private void firewallMessage(Mtp3UserPart mup, Mtp3UserPart mupReturn, int opc, int dpc, int sls, int ni, LongMessageRuleType lmrt, SccpDataMessage message, String reason, HashMap<String, String> lua_hm) { String firewallPolicy = ""; if (SS7FirewallConfig.firewallPolicy == SS7FirewallConfig.FirewallPolicy.DROP_SILENTLY) { firewallPolicy = "DROP_SILENTLY"; } else if (SS7FirewallConfig.firewallPolicy == SS7FirewallConfig.FirewallPolicy.DROP_WITH_SCCP_ERROR) { firewallPolicy = "DROP_WITH_SCCP_ERROR"; sendSccpErrorMessage(mupReturn, dpc, opc, sls, ni, lmrt, message, ReturnCauseValue.NO_TRANSLATION_FOR_ADDRESS); } else if (SS7FirewallConfig.firewallPolicy == SS7FirewallConfig.FirewallPolicy.DNAT_TO_HONEYPOT && dnat_sessions != null && message.getCallingPartyAddress() != null && message.getCallingPartyAddress().getGlobalTitle() != null && message.getCalledPartyAddress() != null && message.getCalledPartyAddress().getGlobalTitle() != null ) { firewallPolicy = "DNAT_TO_HONEYPOT"; GlobalTitle gt = this.sccpProvider.getParameterFactory().createGlobalTitle(SS7FirewallConfig.honeypot_sccp_gt, 0, org.mobicents.protocols.ss7.indicator.NumberingPlan.ISDN_TELEPHONY, null, NatureOfAddress.INTERNATIONAL); SccpAddress sa_dnat = this.sccpProvider.getParameterFactory().createSccpAddress(RoutingIndicator.ROUTING_BASED_ON_GLOBAL_TITLE, gt, 0, message.getCalledPartyAddress().getSubsystemNumber()); SccpAddress sa = message.getCalledPartyAddress(); String session_key = message.getCallingPartyAddress().getGlobalTitle().getDigits(); dnat_sessions.put(session_key, message.getCalledPartyAddress().getGlobalTitle().getDigits() + ":" + message.getCalledPartyAddress().getSubsystemNumber()); message.setCalledPartyAddress(sa_dnat); sendSccpMessage(mup, opc, dpc, sls, ni, lmrt, message); } else if (SS7FirewallConfig.firewallPolicy == SS7FirewallConfig.FirewallPolicy.ALLOW) { firewallPolicy = "ALLOW"; sendSccpMessage(mup, opc, dpc, sls, ni, lmrt, message); } logger.info("Blocked message: Reason [" + reason + "] Policy [" + firewallPolicy + "] " + message.toString()); JSONObject json_alert = new JSONObject(); logger.debug("============ LUA variables ============"); // mThreat alerting MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); for (String key : lua_hm.keySet()) { logger.debug(key + ": " + lua_hm.get(key)); String value = lua_hm.get(key); // Anonymize MSISDN, IMSI if (key.equals("map_imsi") || key.equals("map_msisdn")) { // add salt before hashing value = SS7FirewallConfig.mthreat_salt + value; value = DatatypeConverter.printHexBinary(digest.digest(value.getBytes(StandardCharsets.UTF_8))); } json_alert.put(key, value); } mThreat_alerts.add(json_alert.toJSONString()); } catch (NoSuchAlgorithmException ex) { java.util.logging.Logger.getLogger(SS7Firewall.class.getName()).log(Level.SEVERE, null, ex); } }
Example 12
Source File: Utils.java From TorrentEngine with GNU General Public License v3.0 | 4 votes |
public static Entry getEntry(byte[] torrent) throws Exception { Metafile meta = new Metafile(new ByteArrayInputStream(torrent)); String infohash = DatatypeConverter.printHexBinary(meta.getInfoSha1()); Entry entry = new Entry(infohash, meta.getName(), meta.getComment(), torrent, meta.getFiles()); return entry; }
Example 13
Source File: IeBinaryStateInformation.java From ICS-TestBed-Framework with GNU General Public License v3.0 | 4 votes |
@Override public String toString() { return "BinaryStateInformation (32 bits as hex): " + DatatypeConverter.printHexBinary( new byte[] { (byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8), (byte) (value) }); }
Example 14
Source File: RFXComLighting3Message.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
@Override public State convertToState(RFXComValueSelector valueSelector) throws RFXComException { org.openhab.core.types.State state = UnDefType.UNDEF; if (valueSelector.getItemClass() == NumberItem.class) { if (valueSelector == RFXComValueSelector.SIGNAL_LEVEL) { state = new DecimalType(signalLevel); } else if (valueSelector == RFXComValueSelector.DIMMING_LEVEL) { state = new DecimalType(dimmingLevel); } else { throw new RFXComException("Can't convert " + valueSelector + " to NumberItem"); } } else if (valueSelector.getItemClass() == DimmerItem.class || valueSelector.getItemClass() == RollershutterItem.class) { if (valueSelector == RFXComValueSelector.DIMMING_LEVEL) { state = RFXComLighting3Message.getPercentTypeFromDimLevel(dimmingLevel); } else { throw new RFXComException("Can't convert " + valueSelector + " to DimmerItem/RollershutterItem"); } } else if (valueSelector.getItemClass() == SwitchItem.class) { if (valueSelector == RFXComValueSelector.COMMAND) { switch (command) { case OFF: state = OnOffType.OFF; break; case ON: case BRIGHT: case DIM: state = OnOffType.ON; break; default: throw new RFXComException("Can't convert " + command + " to SwitchItem"); } } else { throw new RFXComException("Can't convert " + valueSelector + " to SwitchItem"); } } else if (valueSelector.getItemClass() == ContactItem.class) { if (valueSelector == RFXComValueSelector.CONTACT) { switch (command) { case OFF: state = OpenClosedType.CLOSED; break; case ON: case BRIGHT: case DIM: state = OpenClosedType.OPEN; break; default: throw new RFXComException("Can't convert " + command + " to ContactItem"); } } else { throw new RFXComException("Can't convert " + valueSelector + " to ContactItem"); } } else if (valueSelector.getItemClass() == StringItem.class) { if (valueSelector == RFXComValueSelector.RAW_DATA) { state = new StringType(DatatypeConverter.printHexBinary(rawMessage)); } else { throw new RFXComException("Can't convert " + valueSelector + " to StringItem"); } } else { throw new RFXComException("Can't convert " + valueSelector + " to " + valueSelector.getItemClass()); } return state; }
Example 15
Source File: StrUtils.java From FastCopy with Apache License 2.0 | 4 votes |
public static String toHexString(byte[] array) { return DatatypeConverter.printHexBinary(array); }
Example 16
Source File: DigestHelper.java From multiapps with Apache License 2.0 | 4 votes |
public static String computeDirectoryCheckSum(Path filePath, String algorithm) throws NoSuchAlgorithmException, IOException { return DatatypeConverter.printHexBinary(computeDirectoryCheckSumBytes(filePath, algorithm)); }
Example 17
Source File: Utils.java From iroha-java with Apache License 2.0 | 4 votes |
/** * Convert bytes to hexstring */ public static String toHex(byte[] b) { return DatatypeConverter.printHexBinary(b); }
Example 18
Source File: Utils.java From Doradus with Apache License 2.0 | 2 votes |
/** * Convert (encode) the given binary value to a hex string. * * @param value Binary value. * @return Hex string representation of same value. * @throws IllegalArgumentException If the given value is null. */ public static String hexFromBinary(byte[] value) throws IllegalArgumentException { return DatatypeConverter.printHexBinary(value); }
Example 19
Source File: RFXComCurrentEnergyMessage.java From openhab1-addons with Eclipse Public License 2.0 | 2 votes |
@Override public State convertToState(RFXComValueSelector valueSelector) throws RFXComException { org.openhab.core.types.State state = UnDefType.UNDEF; if (valueSelector.getItemClass() == NumberItem.class) { if (valueSelector == RFXComValueSelector.SIGNAL_LEVEL) { state = new DecimalType(signalLevel); } else if (valueSelector == RFXComValueSelector.BATTERY_LEVEL) { state = new DecimalType(batteryLevel); } else if (valueSelector == RFXComValueSelector.CHANNEL1_AMPS) { state = new DecimalType(channel1Amps); } else if (valueSelector == RFXComValueSelector.CHANNEL2_AMPS) { state = new DecimalType(channel2Amps); } else if (valueSelector == RFXComValueSelector.CHANNEL3_AMPS) { state = new DecimalType(channel3Amps); } else if (valueSelector == RFXComValueSelector.TOTAL_USAGE) { state = new DecimalType(totalUsage); } else { throw new RFXComException("Can't convert " + valueSelector + " to NumberItem"); } } else if (valueSelector.getItemClass() == StringItem.class) { if (valueSelector == RFXComValueSelector.RAW_DATA) { state = new StringType(DatatypeConverter.printHexBinary(rawMessage)); } else { throw new RFXComException("Can't convert " + valueSelector + " to StringItem"); } } else { throw new RFXComException("Can't convert " + valueSelector + " to " + valueSelector.getItemClass()); } return state; }
Example 20
Source File: RFXComEnergyMessage.java From openhab1-addons with Eclipse Public License 2.0 | 2 votes |
@Override public State convertToState(RFXComValueSelector valueSelector) throws RFXComException { org.openhab.core.types.State state = UnDefType.UNDEF; if (valueSelector.getItemClass() == NumberItem.class) { if (valueSelector == RFXComValueSelector.SIGNAL_LEVEL) { state = new DecimalType(signalLevel); } else if (valueSelector == RFXComValueSelector.BATTERY_LEVEL) { state = new DecimalType(batteryLevel); } else if (valueSelector == RFXComValueSelector.INSTANT_AMPS) { state = new DecimalType(instantAmps); } else if (valueSelector == RFXComValueSelector.TOTAL_AMP_HOURS) { state = new DecimalType(totalAmpHours); } else { throw new RFXComException("Can't convert " + valueSelector + " to NumberItem"); } } else if (valueSelector.getItemClass() == StringItem.class) { if (valueSelector == RFXComValueSelector.RAW_DATA) { state = new StringType(DatatypeConverter.printHexBinary(rawMessage)); } else { throw new RFXComException("Can't convert " + valueSelector + " to StringItem"); } } else { throw new RFXComException("Can't convert " + valueSelector + " to " + valueSelector.getItemClass()); } return state; }