List of usage examples for org.apache.commons.net.util Base64 encodeBase64
public static byte[] encodeBase64(byte[] binaryData)
From source file:org.apache.giraph.comm.netty.SaslNettyServer.java
/** * Encode a password as a base64-encoded char[] array. * @param password as a byte array.//w w w .ja v a2 s. co m * @return password as a char array. */ static char[] encodePassword(byte[] password) { return new String(Base64.encodeBase64(password)).toCharArray(); }
From source file:org.apache.kylin.invertedindex.model.IIDesc.java
public String calculateSignature() { MessageDigest md = null;//w w w . j a v a2 s. c o m try { md = MessageDigest.getInstance("MD5"); StringBuilder sigString = new StringBuilder(); sigString.append(this.name).append("|").append(this.getFactTableName()).append("|") .append(timestampDimension).append("|") .append(JsonUtil.writeValueAsString(this.bitmapDimensions)).append("|") .append(JsonUtil.writeValueAsString(valueDimensions)).append("|") .append(JsonUtil.writeValueAsString(this.metricNames)).append("|").append(sharding).append("|") .append(sliceSize); byte[] signature = md.digest(sigString.toString().getBytes()); return new String(Base64.encodeBase64(signature)); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Failed to calculate signature"); } catch (JsonProcessingException e) { throw new RuntimeException("Failed to calculate signature"); } }
From source file:org.crypto.sse.IEX2LevAMAZON.java
/** * @param args/* w w w . j a v a2 s . c o m*/ * @throws Exception */ @SuppressWarnings("null") public static void main(String[] args) throws Exception { Printer.addPrinter(new Printer(Printer.LEVEL.EXTRA)); // First Job Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "IEX-2Lev"); job.setJarByClass(IEX2LevAMAZON.class); job.setMapperClass(MLK1.class); job.setReducerClass(RLK1.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(Text.class); job.setOutputKeyClass(Text.class); job.setNumReduceTasks(1); job.setOutputValueClass(ArrayListWritable.class); job.setInputFormatClass(FileNameKeyInputFormat.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); // Second Job Configuration conf2 = new Configuration(); Job job2 = Job.getInstance(conf2, "IEX-2Lev"); job2.setJarByClass(IEX2LevAMAZON.class); job2.setMapperClass(MLK2.class); job2.setReducerClass(RLK2.class); job2.setNumReduceTasks(1); job2.setMapOutputKeyClass(Text.class); job2.setMapOutputValueClass(Text.class); job2.setOutputKeyClass(Text.class); job2.setOutputValueClass(ArrayListWritable.class); job2.setInputFormatClass(FileNameKeyInputFormat.class); FileInputFormat.addInputPath(job2, new Path(args[0])); FileOutputFormat.setOutputPath(job2, new Path(args[2])); job.waitForCompletion(true); job2.waitForCompletion(true); // Here add your Amazon Credentials AWSCredentials credentials = new BasicAWSCredentials("XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX"); // create a client connection based on credentials AmazonS3 s3client = new AmazonS3Client(credentials); // create bucket - name must be unique for all S3 users String bucketName = "iexmaptest"; S3Object s3object = s3client.getObject(new GetObjectRequest(bucketName, args[4])); Printer.debugln(s3object.getObjectMetadata().getContentType()); Printer.debugln("" + s3object.getObjectMetadata().getContentLength()); List<String> lines = new ArrayList<String>(); String folderName = "2"; BufferedReader reader = new BufferedReader(new InputStreamReader(s3object.getObjectContent())); String line; int counter = 0; while ((line = reader.readLine()) != null) { // can copy the content locally as well // using a buffered writer lines.add(line); Printer.debugln(line); // upload file to folder String fileName = folderName + "/" + Integer.toString(counter); ByteArrayInputStream input = new ByteArrayInputStream(line.getBytes()); s3client.putObject(bucketName, fileName, input, new ObjectMetadata()); counter++; } Multimap<String, String> lookup = ArrayListMultimap.create(); for (int i = 0; i < lines.size(); i++) { String[] tokens = lines.get(i).split("\\s+"); for (int j = 1; j < tokens.length; j++) { lookup.put(tokens[0], tokens[j]); } } // Loading inverted index that associates files identifiers to keywords lines = new ArrayList<String>(); s3object = s3client.getObject(new GetObjectRequest(bucketName, args[5])); Printer.debugln(s3object.getObjectMetadata().getContentType()); Printer.debugln("" + s3object.getObjectMetadata().getContentLength()); // Loading inverted index that associates keywords to identifiers reader = new BufferedReader(new InputStreamReader(s3object.getObjectContent())); while ((line = reader.readLine()) != null) { lines.add(line); } Multimap<String, String> lookup2 = ArrayListMultimap.create(); for (int i = 0; i < lines.size(); i++) { String[] tokens = lines.get(i).split("\\s+"); for (int j = 1; j < tokens.length; j++) { lookup2.put(tokens[0], tokens[j]); } } // Delete File try { s3client.deleteObject(new DeleteObjectRequest(bucketName, args[4])); } catch (AmazonServiceException ase) { Printer.debugln("Caught an AmazonServiceException."); Printer.debugln("Error Message: " + ase.getMessage()); Printer.debugln("HTTP Status Code: " + ase.getStatusCode()); Printer.debugln("AWS Error Code: " + ase.getErrorCode()); Printer.debugln("Error Type: " + ase.getErrorType()); Printer.debugln("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { Printer.debugln("Caught an AmazonClientException."); Printer.debugln("Error Message: " + ace.getMessage()); } /* * Start of IEX-2Lev construction */ // Generation of keys for IEX-2Lev BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your password :"); String pass = keyRead.readLine(); // You can change the size of the key; Here we set it to 128 List<byte[]> listSK = IEX2Lev.keyGen(128, pass, "salt/salt", 100000); // Generation of Local Multi-maps with Mapper job only without reducer Configuration conf3 = new Configuration(); String testSerialization1 = new String(Base64.encodeBase64(Serializer.serialize(lookup))); String testSerialization2 = new String(Base64.encodeBase64(Serializer.serialize(lookup2))); String testSerialization3 = new String(Base64.encodeBase64(Serializer.serialize(listSK))); // String testSerialization2 = gson.toJson(lookup2); conf3.set("lookup", testSerialization1); conf3.set("lookup2", testSerialization2); conf3.set("setKeys", testSerialization3); Job job3 = Job.getInstance(conf3, "Local MM"); job3.setJarByClass(IEX2LevAMAZON.class); job3.setMapperClass(LocalMM.class); job3.setNumReduceTasks(0); FileInputFormat.addInputPath(job3, new Path(args[2])); FileOutputFormat.setOutputPath(job3, new Path(args[3])); job3.waitForCompletion(true); }
From source file:org.kie.smoke.kie.wb.base.methods.RestSmokeIntegrationTestMethods.java
public void urlsGetDeployments(URL deploymentUrl, String user, String password) throws Exception { // test with normal RestRequestHelper RestRequestHelper requestHelper = getRestRequestHelper(deploymentUrl, user, password); ClientRequest restRequest = requestHelper.createRequest("deployment/"); JaxbDeploymentUnitList depList = get(restRequest, mediaType, JaxbDeploymentUnitList.class); assertNotNull("Null answer!", depList); assertNotNull("Null deployment list!", depList.getDeploymentUnitList()); assertTrue("Empty deployment list!", depList.getDeploymentUnitList().size() > 0); String deploymentId = depList.getDeploymentUnitList().get(0).getIdentifier(); restRequest = requestHelper.createRequest("deployment/" + deploymentId); JaxbDeploymentUnit dep = get(restRequest, mediaType, JaxbDeploymentUnit.class); assertNotNull("Null answer!", dep); assertNotNull("Null deployment list!", dep); assertEquals("Empty status!", JaxbDeploymentStatus.DEPLOYED, dep.getStatus()); // test with HttpURLConnection URL url = new URL(deploymentUrl, deploymentUrl.getPath() + "rest/deployment/"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); String authString = user + ":" + password; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); connection.setRequestProperty("Authorization", "Basic " + authStringEnc); connection.setRequestMethod("GET"); logger.debug(">> [GET] " + url.toExternalForm()); connection.connect();//from www . ja v a 2 s . co m int respCode = connection.getResponseCode(); if (200 != respCode) { logger.warn(connection.getContent().toString()); } assertEquals(200, respCode); JaxbSerializationProvider jaxbSerializer = new JaxbSerializationProvider(); String xmlStrObj = getConnectionContent(connection.getContent()); depList = (JaxbDeploymentUnitList) jaxbSerializer.deserialize(xmlStrObj); assertNotNull("Null answer!", depList); assertNotNull("Null deployment list!", depList.getDeploymentUnitList()); assertTrue("Empty deployment list!", depList.getDeploymentUnitList().size() > 0); }
From source file:org.kie.smoke.wb.rest.KieRemoteRestSmokeIntegrationTest.java
@Test public void testUrlsGetDeployments() throws Exception { // test with normal RestRequestHelper String user = TestConstants.MARY_USER; String password = TestConstants.MARY_PASSWORD; JaxbDeploymentUnitList depList = get(deploymentUrl, "rest/deployment/", mediaType, 200, user, password, JaxbDeploymentUnitList.class); assertNotNull("Null answer!", depList); assertNotNull("Null deployment list!", depList.getDeploymentUnitList()); assertTrue("Empty deployment list!", depList.getDeploymentUnitList().size() > 0); String deploymentId = depList.getDeploymentUnitList().get(0).getIdentifier(); JaxbDeploymentUnit dep = get(deploymentUrl, "rest/deployment/" + deploymentId, mediaType, 200, user, password, JaxbDeploymentUnit.class); assertNotNull("Null answer!", dep); assertNotNull("Null deployment list!", dep); assertEquals("Empty status!", JaxbDeploymentUnit.JaxbDeploymentStatus.DEPLOYED, dep.getStatus()); // test with HttpURLConnection URL url = new URL(deploymentUrl, deploymentUrl.getPath() + "rest/deployment/"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); String authString = user + ":" + password; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); connection.setRequestProperty("Authorization", "Basic " + authStringEnc); connection.setRequestMethod("GET"); logger.debug(">> [GET] " + url.toExternalForm()); connection.connect();/*from w ww. ja v a 2 s.com*/ int respCode = connection.getResponseCode(); if (200 != respCode) { logger.warn(connection.getContent().toString()); } assertEquals(200, respCode); JaxbSerializationProvider jaxbSerializer = ClientJaxbSerializationProvider.newInstance(); String xmlStrObj = getConnectionContent(connection.getContent()); depList = (JaxbDeploymentUnitList) jaxbSerializer.deserialize(xmlStrObj); assertNotNull("Null answer!", depList); assertNotNull("Null deployment list!", depList.getDeploymentUnitList()); assertTrue("Empty deployment list!", depList.getDeploymentUnitList().size() > 0); }
From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteController.java
private void writeBase64String(Writer writer, String str) throws IOException { String tmp = new String(Base64.encodeBase64(str.getBytes())); writeString(writer, tmp);//from ww w . j a v a2 s .co m }
From source file:org.oscarehr.common.dao.RemoteIntegratedDataCopyDao.java
/** * /*ww w .jav a2 s. c om*/ * @param demographicNo * @param obj * @param providerNo * @param facilityId * @return Returns null if it already existed in the database. * @throws Exception */ public RemoteIntegratedDataCopy save(Integer demographicNo, Object obj, String providerNo, Integer facilityId, String type) throws Exception { if (obj == null) { throw new Exception("Can't save null"); } if (type == null) { type = ""; } else { type = "+" + type; } String dataType = obj.getClass().getName() + type; String marshalledObject = ObjectMarshalUtil.marshalToString(obj); MessageDigest md = MessageDigest.getInstance("SHA-1"); md.reset(); byte[] digest = md.digest(marshalledObject.getBytes("UTF-8")); String signature = new String(Base64.encodeBase64(digest), MiscUtils.DEFAULT_UTF8_ENCODING); MiscUtils.getLogger().debug("demo :" + demographicNo + " dataType : " + dataType + " Signature: " + signature + " providerNo " + providerNo + " facilityId " + facilityId); RemoteIntegratedDataCopy remoteIntegratedDataCopy = this.findByDemoTypeSignature(facilityId, demographicNo, dataType, signature); if (remoteIntegratedDataCopy == null) { RemoteIntegratedDataCopy rid = new RemoteIntegratedDataCopy(); rid.setDemographicNo(demographicNo); rid.setDataType(dataType); rid.setData(marshalledObject); rid.setSignature(signature); rid.setProviderNo(providerNo); rid.setFacilityId(facilityId); this.persist(rid); archiveDataCopyExceptThisOne(rid);//Set all other notes besides this one to archived. return rid; } return null; }
From source file:org.roda.core.common.ClassificationPlanUtils.java
public static ObjectNode aipToJSON(IndexedAIP indexedAIP) throws IOException, RequestNotValidException, NotFoundException, GenericException, AuthorizationDeniedException { JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); ModelService model = RodaCoreFactory.getModelService(); ObjectNode node = mapper.createObjectNode(); if (indexedAIP.getTitle() != null) { node = node.put("title", indexedAIP.getTitle()); }//w ww .j a v a 2 s .c om if (indexedAIP.getId() != null) { node = node.put("id", indexedAIP.getId()); } if (indexedAIP.getParentID() != null) { node = node.put("parentId", indexedAIP.getParentID()); } if (indexedAIP.getLevel() != null) { node = node.put("descriptionlevel", indexedAIP.getLevel()); } AIP modelAIP = model.retrieveAIP(indexedAIP.getId()); if (modelAIP.getType() != null) { node = node.put("type", modelAIP.getType()); } if (modelAIP != null) { List<DescriptiveMetadata> descriptiveMetadata = modelAIP.getDescriptiveMetadata(); if (descriptiveMetadata != null && !descriptiveMetadata.isEmpty()) { ArrayNode metadata = mapper.createArrayNode(); for (DescriptiveMetadata dm : descriptiveMetadata) { ObjectNode dmNode = mapper.createObjectNode(); if (dm.getId() != null) { dmNode = dmNode.put("id", dm.getId()); } if (dm.getType() != null) { dmNode = dmNode.put("metadataType", dm.getType()); } if (dm.getVersion() != null) { dmNode = dmNode.put("metadataVersion", dm.getVersion()); } Binary b = model.retrieveDescriptiveMetadataBinary(modelAIP.getId(), dm.getId()); InputStream is = b.getContent().createInputStream(); dmNode = dmNode.put("content", new String(Base64.encodeBase64(IOUtils.toByteArray(is)))); IOUtils.closeQuietly(is); dmNode = dmNode.put("contentEncoding", "Base64"); metadata = metadata.add(dmNode); } node.set("metadata", metadata); } } return node; }
From source file:org.ut.biolab.medsavant.server.mail.CryptoUtils.java
/** * Encrypt the string and return a BASE64 representation suitable for framing or wrapping fish. * * @param str the plaintext string to be encrypted * @return BASE64 encoding of encrypted string *//*from w w w . j a va 2s . c o m*/ public static String encrypt(String str) { try { // Encode bytes to base64 to get a string return new String(Base64.encodeBase64(ENCRYPTOR.doFinal(str.getBytes("UTF-8"))), "UTF-8"); } catch (Exception x) { } return null; }
From source file:org.wso2.carbon.emm.integration.test.EMMIntegrationTest.java
/** * Initializes all EMM APIs required for any integration test by logging into emm web application and * obtain necessary consumer credentials to access them. * @throws EMMIntegrationTestException Custom exception type for any EMM Integration Test *//*ww w . ja va 2 s .c om*/ public EMMIntegrationTest() throws EMMIntegrationTestException { webDriver = new FirefoxDriver(); int timeOutInSeconds = 10; webDriverWait = new WebDriverWait(webDriver, timeOutInSeconds); httpClient = new DefaultHttpClient(); //Following is done to initialize EMM APIs. loginToEmmWebAppViaWebDriver(); //get necessary consumer credentials to access EMM APIs. JSONObject consumerCredentials = getConsumerCredentials(); String consumerKey = (String) consumerCredentials.get("clientkey"); String consumerSecret = (String) consumerCredentials.get("clientsecret"); String combinedCredentials = consumerKey + ":" + consumerSecret; encodedConsumerCredentials = new String(Base64.encodeBase64(combinedCredentials.getBytes())); }