List of usage examples for javax.xml.bind DatatypeConverter parseHexBinary
public static byte[] parseHexBinary(String lexicalXSDHexBinary)
Converts the string argument into an array of bytes.
From source file:org.hyperledger.fabric.sdk.security.CryptoPrimitivesTest.java
@BeforeClass public static void setUpBeforeClass() throws Exception { config = Config.getConfig();/*from ww w . j a va2s .com*/ plainText = DatatypeConverter.parseHexBinary(PLAIN_TEXT_HEX); sig = DatatypeConverter.parseHexBinary(SIGNATURE_HEX); pemCert = DatatypeConverter.parseHexBinary(PEM_CERT_HEX); invalidPemCert = DatatypeConverter.parseHexBinary(INVALID_PEM_CERT); kf = KeyFactory.getInstance("EC"); cf = CertificateFactory.getInstance("X.509"); crypto = new CryptoPrimitives(); crypto.init(); }
From source file:org.jivesoftware.util.StringUtils.java
/** * Turns a hex encoded string into a byte array. It is specifically meant * to "reverse" the toHex(byte[]) method. * * @param hex a hex encoded String to transform into a byte array. * @return a byte array representing the hex String[ */// w ww . j av a2 s . c o m public static byte[] decodeHex(String hex) { return DatatypeConverter.parseHexBinary(hex); }
From source file:org.jupyterkernel.kernel.MessageObject.java
public void read() { try {/*from w w w . jav a2 s . co m*/ ZFrame[] zframes = new ZFrame[zmsg.size()]; zmsg.toArray(zframes); if (zmsg.size() < 7) { throw new RuntimeException( "[jupyter-kernel.jar] Message incomplete. Didn't receive required message parts"); } uuid = zframes[MessageParts.UUID].getData(); String delim = new String(zframes[MessageParts.DELIM].getData(), StandardCharsets.UTF_8); if (!delim.equals(delimiter)) { throw new RuntimeException( "[jupyter-kernel.jar] Incorrectly formatted message. Delimiter <IDS|MSG> not found"); } byte[] header = zframes[MessageParts.HEADER].getData(); byte[] parent = zframes[MessageParts.PARENT].getData(); byte[] meta = zframes[MessageParts.METADATA].getData(); byte[] content = zframes[MessageParts.CONTENT].getData(); byte[] digest = computeSignature(header, parent, meta, content); byte[] hmac = zframes[MessageParts.HMAC].getData(); // hmac is an UTF-8 string and has to be converted into a byte array first hmac = DatatypeConverter.parseHexBinary(new String(hmac)); mildlySecureMACCompare(digest, hmac); JSONObject jsonHeader = new JSONObject(new String(header, StandardCharsets.UTF_8)); if (null == T_JSON.message_protocol_version) { String protocolVersion = (String) jsonHeader.get("version"); checkAllowedProtocolVersion(protocolVersion); // set protocol version for protocol specific serialization / deserialization T_JSON.setProtocolVersion(protocolVersion); } msg.header = (T_header) T_JSON.fromJSON("T_header", jsonHeader); msg.parent_header = (T_header) T_JSON.fromJSON("T_header", new JSONObject(new String(parent, StandardCharsets.UTF_8))); msg.metadata = new JSONObject(new String(meta, StandardCharsets.UTF_8)); msg.content = T_JSON.fromJSON("T_" + msg.header.msg_type, new JSONObject(new String(content, StandardCharsets.UTF_8))); } finally { zmsg.destroy(); } }
From source file:org.kalypso.service.wps.utils.simulation.WPSSimulationDataProvider.java
public static Object parseComplexValue(final ComplexValueType complexValue) throws SimulationException { final String mimeType = complexValue.getFormat(); final List<Object> content = complexValue.getContent(); if (content.size() == 0) return null; final Object firstContent = content.get(0); final String textContent; if (firstContent instanceof String) { textContent = (String) firstContent; } else if (firstContent instanceof Element) { final DOMSource domSource = new DOMSource((Element) firstContent); final TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer;//from w ww . j ava 2s. c o m try { transformer = factory.newTransformer(); final StringWriter writer = new StringWriter(); transformer.transform(domSource, new StreamResult(writer)); textContent = writer.toString(); } catch (final Exception e) { throw new SimulationException( Messages.getString("org.kalypso.service.wps.utils.simulation.WPSSimulationDataProvider.2"), //$NON-NLS-1$ e); } } else { throw new SimulationException( Messages.getString("org.kalypso.service.wps.utils.simulation.WPSSimulationDataProvider.2")); //$NON-NLS-1$ } // distinguish by mime type, default to binary if (TYPE_GML.equals(mimeType)) { final StringReader reader = new StringReader(textContent); final InputSource inputSource = new InputSource(reader); try { final String schema = complexValue.getSchema(); if (schema == null || schema.isEmpty()) { return GmlSerializer.createGMLWorkspace(inputSource, null, null, null); } final URL schemaLocationHint = new URL(schema); return GmlSerializer.createGMLWorkspace(inputSource, schemaLocationHint, null, null); } catch (final Exception e) { throw new SimulationException( Messages.getString("org.kalypso.service.wps.utils.simulation.WPSSimulationDataProvider.2"), //$NON-NLS-1$ e); } } else { try { // parse as hexBinary // TODO: why not base64 encoded byte[]? final byte[] bytes = DatatypeConverter.parseHexBinary(textContent); final File file = FileUtilities.createNewUniqueFile("complexValue_", FileUtilities.TMP_DIR); //$NON-NLS-1$ FileUtils.writeByteArrayToFile(file, bytes); return file.toURI().toURL(); } catch (final IOException e) { throw new SimulationException( Messages.getString("org.kalypso.service.wps.utils.simulation.WPSSimulationDataProvider.3"), //$NON-NLS-1$ e); } } }
From source file:org.openhab.binding.ebus.EBusGenericBindingProvider.java
@Override public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException { super.processBindingConfiguration(context, item, bindingConfig); logger.debug("Process binding cfg for {} with settings {} [Context:{}]", item.getName(), bindingConfig, context);//from w ww . j a v a 2s . c o m EBusBindingConfig config = new EBusBindingConfig(); for (String set : bindingConfig.trim().split(",")) { String[] configParts = set.split(":"); if (configParts.length > 2) { throw new BindingConfigParseException( "eBus binding configuration must not contain more than two parts"); } configParts[0] = configParts[0].trim().toLowerCase(); configParts[1] = configParts[1].trim(); if (configParts[0].equals("data")) { config.map.put(configParts[0], EBusUtils.toByteArray(configParts[1])); } else if (configParts[0].equals("src")) { config.map.put(configParts[0], DatatypeConverter.parseHexBinary(configParts[1])[0]); } else if (configParts[0].equals("dst")) { config.map.put(configParts[0], DatatypeConverter.parseHexBinary(configParts[1])[0]); } else if (configParts[0].equals("refresh")) { config.map.put(configParts[0], Integer.parseInt(configParts[1])); } else if (configParts[0].startsWith("data-")) { if (!config.map.containsKey("data-map")) { config.map.put("data-map", new HashMap<String, byte[]>()); } @SuppressWarnings("unchecked") HashMap<String, byte[]> m = (HashMap<String, byte[]>) config.map.get("data-map"); String key = configParts[0].substring(5); m.put(key, EBusUtils.toByteArray(configParts[1])); } else { config.map.put(configParts[0], configParts[1]); } } addBindingConfig(item, config); }
From source file:org.openhab.binding.km200.internal.KM200Device.java
public void setMD5Salt(String salt) { MD5Salt = DatatypeConverter.parseHexBinary(salt); RecreateKeys(); }
From source file:org.openhab.binding.km200.internal.KM200Device.java
public void setCryptKeyPriv(String key) { cryptKeyPriv = DatatypeConverter.parseHexBinary(key); }
From source file:org.openhab.binding.nikobus.internal.util.CRCUtil.java
/** * Calculate the CRC16-CCITT checksum on the input string and return the * input string with the checksum appended. * /*from w w w .j ava 2 s.c om*/ * @param input * String representing hex numbers. * @return input string + CRC. */ public static String appendCRC(String input) { if (input == null) { return null; } int check = CRC_INIT; for (byte b : DatatypeConverter.parseHexBinary(input)) { for (int i = 0; i < 8; i++) { if (((b >> (7 - i) & 1) == 1) ^ ((check >> 15 & 1) == 1)) { check = check << 1; check = check ^ POLYNOMIAL; } else { check = check << 1; } } } check = check & CRC_INIT; String checksum = StringUtils.leftPad(Integer.toHexString(check), 4, "0"); return (input + checksum).toUpperCase(); }
From source file:org.openhab.binding.onkyo.internal.OnkyoAlbumArt.java
public byte[] getAlbumArt() throws IllegalArgumentException { byte[] data = null; if (state == State.READY) { switch (imageType) { case BMP: case JPEG: data = DatatypeConverter.parseHexBinary(albumArtStringBuilder.toString()); break; case URL: data = downloadAlbumArt(coverArtUrl); //Workaround firmware bug providing incorrect headers causing them to be seen as body instead. if (data != null) { int bodyLength = data.length; int i = new String(data).indexOf("image/"); if (i > 0) { while (i < bodyLength && data[i] != '\r') { i++;//from ww w . j a v a 2s. c om } while (i < bodyLength && (data[i] == '\r' || data[i] == '\n')) { i++; } data = Arrays.copyOfRange(data, i, bodyLength); logger.trace("Onkyo fixed picture data @ {}: {} ", i, new String(data)); } } break; case NONE: default: } return data; } throw new IllegalArgumentException("Illegal Album Art"); }
From source file:org.opentestsystem.unittest.db.export.UUIDDataType.java
@Override public Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException { String value = resultSet.getString(column); if (value == null || resultSet.wasNull()) { return null; }//from w w w .j av a 2s . c o m String s = value.replace("-", ""); byte[] myBytes = DatatypeConverter.parseHexBinary(s); String encodedBase64 = Base64.encodeBase64String(myBytes); return encodedBase64; }