List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:li.poi.services.docx.resource.MailMerge.java
@Path("/test") @GET//from ww w .ja va 2 s . co m @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public MailMergeResponse test() throws Docx4JException { MailMergeResponse mail = new MailMergeResponse(); File tmp = null; try { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!"); tmp = File.createTempFile("document", "docx"); wordMLPackage.save(tmp); mail.setDocument(Base64.encodeBase64String(IOUtils.toByteArray(new FileInputStream(tmp)))); mail.setError("success"); mail.setDocumentName(tmp.getName()); } catch (IOException e) { e.printStackTrace(); mail.setError("error... " + e.getMessage()); } finally { if (tmp != null) { boolean deleted = tmp.delete(); if (!deleted) { log.warn("file not deleted " + tmp.getAbsolutePath()); } } } return mail; }
From source file:edu.kit.scc.cdmi.rest.CdmiObjectTest.java
@Test public void testGetObjectByIdNotFound() { String authString = Base64.encodeBase64String((restUser + ":" + restPassword).getBytes()); Response response = given().header("Authorization", "Basic " + authString).and() .header("Content-Type", "application/cdmi-object").when().get("/cdmi_objectid/invalid").then() .statusCode(org.apache.http.HttpStatus.SC_NOT_FOUND).extract().response(); log.debug("Response {}", response.asString()); }
From source file:com.consol.citrus.functions.core.EncodeBase64Function.java
/** * {@inheritDoc}/*from www.j a v a 2s . co m*/ */ public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) { throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!"); } String charset = "UTF-8"; if (parameterList.size() > 1) { charset = parameterList.get(1); } try { return Base64.encodeBase64String(parameterList.get(0).getBytes(charset)); } catch (UnsupportedEncodingException e) { throw new CitrusRuntimeException("Unsupported character encoding", e); } }
From source file:com.google.jenkins.plugins.googlecontainerregistryauth.GoogleContainerRegistryTokenSource.java
/** {@inheritDoc} */ @NonNull//from ww w . ja v a2s.c o m @Override public DockerRegistryToken convert(GoogleContainerRegistryCredential credential) throws AuthenticationTokenException { return new DockerRegistryToken(credential.getEmail(), Base64.encodeBase64String((credential.getUsername() + ":" + credential.getPassword().getPlainText()) .getBytes(Charsets.UTF_8))); }
From source file:com.hp.application.automation.tools.EncryptionUtils.java
public static String Encrypt(String text, String key) throws Exception { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] keyBytes = new byte[16]; byte[] b = key.getBytes("UTF-8"); int len = b.length; if (len > keyBytes.length) len = keyBytes.length;/* w ww . j av a 2 s .co m*/ System.arraycopy(b, 0, keyBytes, 0, len); SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); IvParameterSpec ivSpec = new IvParameterSpec(keyBytes); cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); byte[] results = cipher.doFinal(text.getBytes("UTF-8")); return Base64.encodeBase64String(results); }
From source file:edu.kit.scc.cdmi.rest.CapabilitiesTest.java
@Test public void testGetRootCapabilities() { String authString = Base64.encodeBase64String((restUser + ":" + restPassword).getBytes()); Response response = given().header("Authorization", "Basic " + authString).and() .header("Content-Type", "application/cdmi-capability").when().get("/cdmi_capabilities").then() .statusCode(org.apache.http.HttpStatus.SC_OK).extract().response(); log.debug("Response {}", response.asString()); }
From source file:com.shareplaylearn.resources.test.AccessTokenTest.java
public OauthPasswordFlow.LoginInfo testPost() throws IOException { HttpPost httpPost = new HttpPost(ACCESS_TOKEN_RESOURCE); String credentialsString = username + ":" + password; httpPost.addHeader("Authorization", Base64.encodeBase64String(credentialsString.getBytes(StandardCharsets.UTF_8))); try (CloseableHttpResponse response = BackendTest.httpClient.execute(httpPost)) { BackendTest.ProcessedHttpResponse processedHttpResponse = new BackendTest.ProcessedHttpResponse( response);//from www. java2s .c o m if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Error testing access token endpoint: " + processedHttpResponse.completeMessage); } return new Gson().fromJson(processedHttpResponse.entity, OauthPasswordFlow.LoginInfo.class); } }
From source file:com.example.license.RSAUtil.java
public static String encrypt(String data, PrivateKey pri_key) throws Exception { // Cipher??// w ww . j a v a 2 s . c om Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); // SecureRandom random = new SecureRandom(); // ?Cipher? cipher.init(Cipher.ENCRYPT_MODE, pri_key); byte[] results = cipher.doFinal(data.getBytes()); // http://tripledes.online-domain-tools.com/?? for (int i = 0; i < results.length; i++) { System.out.print(results[i] + " "); } System.out.println(); // ??Base64? return Base64.encodeBase64String(results); }
From source file:com.screenslicer.core.util.Email.java
public static void sendResults(EmailExport export) { if (WebApp.DEV) { return;// w w w. jav a2 s.co m } Map<String, Object> params = new HashMap<String, Object>(); params.put("key", Config.instance.mandrillKey()); List<Map<String, String>> to = new ArrayList<Map<String, String>>(); for (int i = 0; i < export.recipients.length; i++) { to.add(CommonUtil.asMap("email", "name", "type", export.recipients[i], export.recipients[i].split("@")[0], "to")); } List<Map<String, String>> attachments = new ArrayList<Map<String, String>>(); for (Map.Entry<String, byte[]> entry : export.attachments.entrySet()) { attachments.add(CommonUtil.asMap("type", "name", "content", new Tika().detect(entry.getValue()), entry.getKey(), Base64.encodeBase64String(entry.getValue()))); } params.put("message", CommonUtil.asObjMap("track_clicks", "track_opens", "html", "text", "headers", "subject", "from_email", "from_name", "to", "attachments", false, false, "Results attached.", "Results attached.", CommonUtil.asMap("Reply-To", Config.instance.mandrillEmail()), export.title, Config.instance.mandrillEmail(), Config.instance.mandrillEmail(), to, attachments)); params.put("async", true); HttpURLConnection conn = null; String resp = null; Log.info("Sending email: " + export.title, false); try { conn = (HttpURLConnection) new URL("https://mandrillapp.com/api/1.0/messages/send.json") .openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("User-Agent", "Mandrill-Curl/1.0"); String data = CommonUtil.gson.toJson(params, CommonUtil.objectType); byte[] bytes = data.getBytes("utf-8"); conn.setRequestProperty("Content-Length", "" + bytes.length); OutputStream os = conn.getOutputStream(); os.write(bytes); conn.connect(); resp = IOUtils.toString(conn.getInputStream(), "utf-8"); if (resp.contains("\"rejected\"") || resp.contains("\"invalid\"")) { Log.warn("Invalid/rejected email addreses"); } } catch (Exception e) { Log.exception(e); } }
From source file:com.springcryptoutils.core.mac.Base64EncodedMacImpl.java
public String digest(String message) { return Base64.encodeBase64String(mac.digest(Base64.decodeBase64(message))); }