List of usage examples for org.apache.commons.net.util Base64 decodeBase64
public static byte[] decodeBase64(byte[] base64Data)
From source file:org.openhab.binding.max.internal.message.L_Message.java
public Collection<? extends Device> updateDevices(List<Device> devices, List<DeviceConfiguration> configurations) { byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes()); MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage); while (tokenizer.hasMoreElements()) { byte[] token = tokenizer.nextElement(); String rfAddress = Utils.toHex(token[0] & 0xFF, token[1] & 0xFF, token[2] & 0xFF); //logger.debug("token: "+token+" rfaddress: "+rfAddress); Device foundDevice = null;//from ww w.j ava 2 s . c o m for (Device device : devices) { //logger.debug(device.getRFAddress().toUpperCase()+ " vs "+rfAddress); if (device.getRFAddress().toUpperCase().equals(rfAddress)) { //logger.debug("Updating device..."+rfAddress); foundDevice = device; } } if (foundDevice != null) { foundDevice = Device.update(token, configurations, foundDevice); //devices.remove(token); //devices.add(foundDevice); } else { Device tempDevice = Device.create(token, configurations); if (tempDevice != null) { devices.add(tempDevice); } } } return devices; }
From source file:org.openhab.binding.max.internal.message.MMessage.java
public MMessage(String raw) { super(raw);/*from w ww. ja v a 2 s . c o m*/ hasConfiguration = false; String[] tokens = this.getPayload().split(Message.DELIMETER); if (tokens.length <= 1) { logger.debug("No rooms defined. Configure your Max! Cube"); hasConfiguration = false; return; } try { byte[] bytes = Base64.decodeBase64(tokens[2].getBytes(StandardCharsets.UTF_8)); hasConfiguration = true; logger.trace("*** M Message trace**** "); logger.trace("\tMagic? (expect 86) : {}", (int) bytes[0]); logger.trace("\tVersion? (expect 2): {}", (int) bytes[1]); logger.trace("\t#defined rooms in M: {}", (int) bytes[2]); rooms = new ArrayList<>(); devices = new ArrayList<>(); int roomCount = bytes[2]; int byteOffset = 3; // start of rooms /* process room */ for (int i = 0; i < roomCount; i++) { int position = bytes[byteOffset++]; int nameLength = bytes[byteOffset++] & 0xff; byte[] data = new byte[nameLength]; System.arraycopy(bytes, byteOffset, data, 0, nameLength); byteOffset += nameLength; String name = new String(data, StandardCharsets.UTF_8); String rfAddress = Utils.toHex((bytes[byteOffset] & 0xff), (bytes[byteOffset + 1] & 0xff), (bytes[byteOffset + 2] & 0xff)); byteOffset += 3; rooms.add(new RoomInformation(position, name, rfAddress)); } /* process devices */ int deviceCount = bytes[byteOffset++]; for (int deviceId = 0; deviceId < deviceCount; deviceId++) { DeviceType deviceType = DeviceType.create(bytes[byteOffset++]); String rfAddress = Utils.toHex((bytes[byteOffset] & 0xff), (bytes[byteOffset + 1] & 0xff), (bytes[byteOffset + 2] & 0xff)); byteOffset += 3; final StringBuilder serialNumberBuilder = new StringBuilder(10); for (int i = 0; i < 10; i++) { serialNumberBuilder.append((char) bytes[byteOffset++]); } int nameLength = bytes[byteOffset++] & 0xff; byte[] data = new byte[nameLength]; System.arraycopy(bytes, byteOffset, data, 0, nameLength); byteOffset += nameLength; String deviceName = new String(data, StandardCharsets.UTF_8); int roomId = bytes[byteOffset++] & 0xff; devices.add(new DeviceInformation(deviceType, serialNumberBuilder.toString(), rfAddress, deviceName, roomId)); } } catch (Exception e) { logger.debug("Unknown error parsing the M Message: {}", e.getMessage(), e); logger.debug("\tRAW : {}", this.getPayload()); } }
From source file:org.openhab.binding.max.internal.message.M_Message.java
public M_Message(String raw) { super(raw);/*from w w w. j a va 2 s . c o m*/ hasConfiguration = false; String[] tokens = this.getPayload().split(Message.DELIMETER); if (tokens.length > 1) try { byte[] bytes = Base64.decodeBase64(tokens[2].getBytes()); hasConfiguration = true; logger.trace("*** M_Message trace**** "); logger.trace("\tMagic? (expect 86) : {}", (int) bytes[0]); logger.trace("\tVersion? (expect 2): {}", (int) bytes[1]); logger.trace("\t#defined rooms in M: {}", (int) bytes[2]); rooms = new ArrayList<RoomInformation>(); devices = new ArrayList<DeviceInformation>(); int roomCount = bytes[2]; int byteOffset = 3; // start of rooms /* process room */ for (int i = 0; i < roomCount; i++) { int position = bytes[byteOffset++]; int nameLength = (int) bytes[byteOffset++] & 0xff; byte[] data = new byte[nameLength]; System.arraycopy(bytes, byteOffset, data, 0, nameLength); byteOffset += nameLength; String name = new String(data, "UTF-8"); String rfAddress = Utils.toHex(((int) bytes[byteOffset] & 0xff), ((int) bytes[byteOffset + 1] & 0xff), ((int) bytes[byteOffset + 2] & 0xff)); byteOffset += 3; rooms.add(new RoomInformation(position, name, rfAddress)); } /* process devices */ int deviceCount = bytes[byteOffset++]; for (int deviceId = 0; deviceId < deviceCount; deviceId++) { DeviceType deviceType = DeviceType.create(bytes[byteOffset++]); String rfAddress = Utils.toHex(((int) bytes[byteOffset] & 0xff), ((int) bytes[byteOffset + 1] & 0xff), ((int) bytes[byteOffset + 2] & 0xff)); byteOffset += 3; String serialNumber = ""; for (int i = 0; i < 10; i++) { serialNumber += (char) bytes[byteOffset++]; } int nameLength = (int) bytes[byteOffset++] & 0xff; byte[] data = new byte[nameLength]; System.arraycopy(bytes, byteOffset, data, 0, nameLength); byteOffset += nameLength; String deviceName = new String(data, "UTF-8"); int roomId = (int) bytes[byteOffset++] & 0xff; devices.add(new DeviceInformation(deviceType, serialNumber, rfAddress, deviceName, roomId)); } } catch (Exception e) { logger.info("Unknown error parsing the M Message: {}", e.getMessage(), e); logger.debug("\tRAW : {}", this.getPayload()); } else { logger.info("No rooms defined. Configure your Max!Cube"); hasConfiguration = false; } }
From source file:org.openhab.binding.max.internal.message.NMessage.java
/** * The {@link: NMessage} contains information about a newly discovered Device * * @param raw String with raw message//w w w. j av a 2 s .co m */ public NMessage(String raw) { super(raw); String msgPayload = this.getPayload(); if (msgPayload.length() > 0) { try { decodedPayload = new String(Base64.decodeBase64(msgPayload), StandardCharsets.UTF_8); byte[] bytes = Base64.decodeBase64(msgPayload); deviceType = DeviceType.create(bytes[0] & 0xFF); rfAddress = Utils.toHex(bytes[1] & 0xFF, bytes[2] & 0xFF, bytes[3] & 0xFF); byte[] data = new byte[10]; System.arraycopy(bytes, 4, data, 0, 10); serialnr = new String(data, StandardCharsets.UTF_8); } catch (Exception e) { logger.debug("Exception occurred during parsing of N message: {}", e.getMessage(), e); } } else { logger.debug("No device found during inclusion"); } }
From source file:org.openhab.binding.max.internal.message.N_Message.java
/** * The {@link: N_Message} contains information about a newly discovered Device * * @param raw String with raw message/*from w w w .j a v a 2 s .c o m*/ */ public N_Message(String raw) { super(raw); String msgPayload = this.getPayload(); if (msgPayload.length() > 0) { try { decodedPayload = new String(Base64.decodeBase64(msgPayload), "UTF-8"); byte[] bytes = Base64.decodeBase64(msgPayload); deviceType = DeviceType.create(bytes[0] & 0xFF); rfAddress = Utils.toHex(bytes[1] & 0xFF, bytes[2] & 0xFF, bytes[3] & 0xFF); byte[] data = new byte[10]; System.arraycopy(bytes, 4, data, 0, 10); serialnr = new String(data, "UTF-8"); } catch (Exception e) { logger.debug("Exception occurred during parsing of N message: {}", e.getMessage(), e); } } else { logger.debug("No device found during inclusion"); } }
From source file:org.openhab.io.net.http.SecureHttpContext.java
/** * Parses the given <code>authHeader</code>, extracts username and password * and tries to authenticate with these credentials. If the login succeeded * it sets the appropriate headers to the <code>request</code> * //from w ww .ja v a 2 s . c o m * @param request * @param authHeader * @param realm * * @return <code>true</code> if the login succeeded and <code>false</code> * in all other cases. */ private boolean computeAuthHeader(HttpServletRequest request, final String authHeader, final String realm) { logger.trace("received authentication request '{}'", authHeader); String[] authHeaders = authHeader.trim().split(" "); if (authHeaders.length == 2) { String authType = StringUtils.trim(authHeaders[0]); String authInfo = StringUtils.trim(authHeaders[1]); if (HttpServletRequest.BASIC_AUTH.equalsIgnoreCase(authType)) { String authInfoString = new String(Base64.decodeBase64(authInfo)); String[] authInfos = authInfoString.split(":"); if (authInfos.length < 2) { logger.warn("authInfos '{}' must contain two elements separated by a colon", authInfoString); return false; } String username = authInfos[0]; String password = authInfos[1]; Subject subject = authenticate(realm, username, password); if (subject != null) { request.setAttribute(HttpContext.AUTHENTICATION_TYPE, HttpServletRequest.BASIC_AUTH); request.setAttribute(HttpContext.REMOTE_USER, username); logger.trace("authentication of user '{}' succeeded!", username); return true; } } else { logger.warn("we don't support '{}' authentication -> processing aborted", authType); } } else { logger.warn("authentication header '{}' must contain of two parts separated by a blank", authHeader); } return false; }
From source file:org.trustedanalytics.cfbroker.config.HadoopZipConfiguration.java
private Map<String, String> getAsMap() throws IOException, XPathExpressionException { InputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(Base64.decodeBase64(encodedZip))); ZipEntry zipFileEntry;/*w w w . j a v a 2s . c o m*/ Map<String, String> map = new HashMap<>(); while ((zipFileEntry = ((ZipInputStream) zipInputStream).getNextEntry()) != null) { if (!zipFileEntry.getName().endsWith("-site.xml")) { continue; } byte[] bytes = IOUtils.toByteArray(zipInputStream); InputSource is = new InputSource(new ByteArrayInputStream(bytes)); XPath xPath = XPathFactory.newInstance().newXPath(); NodeList nodeList = (NodeList) xPath.evaluate(ConfigConstants.CONF_PROPERTY_XPATH, is, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { Node propNode = nodeList.item(i); String key = (String) xPath.evaluate("name/text()", propNode, XPathConstants.STRING); String value = (String) xPath.evaluate("value/text()", propNode, XPathConstants.STRING); map.put(key, value); } } return map; }
From source file:org.ut.biolab.medsavant.server.mail.CryptoUtils.java
/** * Decrypt a BASE64 encoded encrypted string. * //w ww .jav a 2 s. co m * @param str BASE64 representation of encrypted string * @return plain-text */ public static String decrypt(String str) { try { return new String(DECRYPTOR.doFinal(Base64.decodeBase64(str.getBytes("UTF-8")))); } catch (Exception x) { } return null; }
From source file:sources.MyCrypto.java
public static String decrypt(String texto) { return new String(Base64.decodeBase64(texto.getBytes())); }