List of usage examples for org.apache.commons.net.util Base64 encodeBase64String
public static String encodeBase64String(byte[] binaryData)
From source file:ezbake.security.service.registration.handler.EzSecurityRegistrationHandler.java
private String calculatePassphrase(PKeyCrypto crypto) throws PKeyCryptoException { String cn = SecurityID.ReservedSecurityId.Registration.getCn(); byte[] signedData = crypto.sign(cn.getBytes()); return Base64.encodeBase64String(signedData); }
From source file:io.hops.hopsworks.api.project.ProjectService.java
@POST @Path("{id}/downloadCert") @Produces(MediaType.APPLICATION_JSON)/* w w w . j a v a 2s . co m*/ @AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER }) public Response downloadCerts(@PathParam("id") Integer id, @FormParam("password") String password, @Context HttpServletRequest req) throws ProjectException, HopsSecurityException, DatasetException { Users user = userFacade.findByEmail(req.getRemoteUser()); if (user.getEmail().equals(Settings.AGENT_EMAIL) || !authController.validatePwd(user, password, req)) { throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CERT_ACCESS_DENIED, Level.FINE); } Project project = projectController.findProjectById(id); String keyStore = ""; String trustStore = ""; try { //Read certs from database and stream them out certificateMaterializer.materializeCertificatesLocal(user.getUsername(), project.getName()); CertificateMaterializer.CryptoMaterial material = certificateMaterializer .getUserMaterial(user.getUsername(), project.getName()); keyStore = Base64.encodeBase64String(material.getKeyStore().array()); trustStore = Base64.encodeBase64String(material.getTrustStore().array()); String certPwd = new String(material.getPassword()); //Pop-up a message from admin messageController.send(user, userFacade.findByEmail(Settings.SITE_EMAIL), "Certificate Info", "", "An email was sent with the password for your project's certificates. If an email does not arrive shortly, " + "please check spam first and then contact the administrator.", ""); emailBean.sendEmail(user.getEmail(), Message.RecipientType.TO, "Hopsworks certificate information", "The password for keystore and truststore is:" + certPwd); } catch (Exception ex) { LOGGER.log(Level.SEVERE, null, ex); throw new DatasetException(RESTCodes.DatasetErrorCode.DOWNLOAD_ERROR, Level.SEVERE, "projectId: " + id, ex.getMessage(), ex); } finally { certificateMaterializer.removeCertificatesLocal(user.getUsername(), project.getName()); } CertsDTO certsDTO = new CertsDTO("jks", keyStore, trustStore); return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(certsDTO).build(); }
From source file:org.apache.kudu.mapreduce.KuduTableMapReduceUtil.java
/** * Returns the provided predicates as a Base64 encoded string. * @param predicates the predicates to encode * @return the encoded predicates//from ww w.j a v a 2 s. co m */ static String base64EncodePredicates(List<KuduPredicate> predicates) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (KuduPredicate predicate : predicates) { predicate.toPB().writeDelimitedTo(baos); } return Base64.encodeBase64String(baos.toByteArray()); }
From source file:org.apache.tajo.storage.json.JsonLineSerializer.java
private void putValue(JSONObject json, String fullPath, String[] pathElements, int depth, int fieldIndex, Tuple input) throws IOException { String fieldName = pathElements[depth]; if (input.isBlankOrNull(fieldIndex)) { return;//w ww .ja va 2 s . c om } switch (types.get(fullPath)) { case BOOLEAN: json.put(fieldName, input.getBool(fieldIndex)); break; case INT1: case INT2: json.put(fieldName, input.getInt2(fieldIndex)); break; case INT4: json.put(fieldName, input.getInt4(fieldIndex)); break; case INT8: json.put(fieldName, input.getInt8(fieldIndex)); break; case FLOAT4: json.put(fieldName, input.getFloat4(fieldIndex)); break; case FLOAT8: json.put(fieldName, input.getFloat8(fieldIndex)); break; case TEXT: case VARCHAR: json.put(fieldName, input.getText(fieldIndex)); break; case CHAR: case DATE: case INTERVAL: json.put(fieldName, input.asDatum(fieldIndex).asChars()); break; case TIMESTAMP: json.put(fieldName, TimestampDatum.asChars(input.getTimeDate(fieldIndex), timezone, false)); break; case TIME: json.put(fieldName, input.asDatum(fieldIndex).asChars()); break; case BIT: case BINARY: case BLOB: case VARBINARY: json.put(fieldName, Base64.encodeBase64String(input.getBytes(fieldIndex))); break; case NULL_TYPE: break; case RECORD: JSONObject record = json.containsKey(fieldName) ? (JSONObject) json.get(fieldName) : new JSONObject(); json.put(fieldName, record); putValue(record, fullPath + "/" + pathElements[depth + 1], pathElements, depth + 1, fieldIndex, input); break; default: throw new TajoRuntimeException( new NotImplementedException("" + types.get(fullPath).name() + " for json")); } }
From source file:org.kududb.mapreduce.KuduTableMapReduceUtil.java
static String base64EncodePredicates(List<ColumnRangePredicate> predicates) { byte[] predicateBytes = ColumnRangePredicate.toByteArray(predicates); return Base64.encodeBase64String(predicateBytes); }
From source file:org.openhab.binding.max.internal.command.SCommand.java
/** * Returns the Base64 encoded command string to be sent via the MAX! * protocol./*from ww w. jav a2 s . co m*/ * * @return the string representing the command */ @Override public String getCommandString() { final String baseString; if (roomId == 0) { baseString = BASE_STRING_S; } else { baseString = BASE_STRING_G; } final String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits); final String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; }
From source file:org.openhab.binding.max.internal.command.SConfigCommand.java
/** * Returns the Base64 encoded command string to be sent via the MAX! Cube. * * @return the string representing the command *//*from w ww . j a v a 2s . c o m*/ @Override public String getCommandString() { final StringBuilder commandConfigString = new StringBuilder(); for (byte b : commandBytes) { commandConfigString.append(String.format("%02X", b)); } String commandString = baseString + rfAddress; if (configCommandType == ConfigCommandType.SetRoom || configCommandType == ConfigCommandType.RemoveRoom) { commandString = commandString + commandConfigString + Utils.toHex(roomId); } else { commandString = commandString + Utils.toHex(roomId) + commandConfigString; } String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; }
From source file:org.openhab.binding.max.internal.command.S_Command.java
/** * Returns the Base64 encoded command string to be sent via the MAX! * protocol./*from ww w . j a v a2s . com*/ * * @return the string representing the command */ @Override public String getCommandString() { String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits); String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; }
From source file:org.openhab.binding.max.internal.command.S_ConfigCommand.java
/** * Returns the Base64 encoded command string to be sent via the MAX! Cube. * * @return the string representing the command *///from w w w. j av a 2 s .co m @Override public String getCommandString() { StringBuilder commandConfigString = new StringBuilder(); for (byte b : commandBytes) { commandConfigString.append(String.format("%02X", b)); } String commandString = baseString + rfAddress; if (configCommandType == ConfigCommandType.SetRoom || configCommandType == ConfigCommandType.RemoveRoom) { commandString = commandString + commandConfigString + Utils.toHex(roomId); } else { commandString = commandString + Utils.toHex(roomId) + commandConfigString; } String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; }
From source file:org.openhab.binding.max.internal.message.S_Command.java
/** * Returns the Base64 encoded command string to be sent via the MAX! * protocol./* www .j a va 2 s. c o m*/ * * @return the string representing the command */ public String getCommandString() { String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits); String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; }