List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:fi.internetix.edelphi.taglib.chartutil.PngImageHTMLEmitter.java
public String generateHTML() throws BirtException { byte[] chartData = ChartModelProvider.getChartData(chartModel, "PNG"); StringBuilder dataUrlBuilder = new StringBuilder(); dataUrlBuilder.append("data:image/png;base64,"); dataUrlBuilder.append(Base64.encodeBase64String(chartData)); StringBuilder html = new StringBuilder(); if (dynamicSize) { html.append(String.format("<img src=\"%s\" width=\"100%%\">", dataUrlBuilder.toString())); } else {// w w w . ja va2s . c o m html.append(String.format("<img src=\"%s\" width=\"%s\" height=\"%s\">", dataUrlBuilder.toString(), width, height)); } html.append("<br/>"); return html.toString(); }
From source file:com.netflix.spinnaker.clouddriver.artifacts.config.BasicAuth.java
default Optional<String> getBasicAuthHeader() { String usernamePassword = null; if (StringUtils.isNotEmpty(getUsernamePasswordFile())) { usernamePassword = CredentialReader.credentialsFromFile(getUsernamePasswordFile()); } else if (StringUtils.isNotEmpty(getUsername()) && StringUtils.isNotEmpty(getPassword())) { usernamePassword = getUsername() + ":" + getPassword(); }//from ww w . j av a2 s . c o m return Optional.ofNullable(usernamePassword).map(s -> "Basic " + Base64.encodeBase64String(s.getBytes())); }
From source file:com.cnd.greencube.web.base.util.RSAUtils.java
/** * /*from w ww . j a v a 2 s. co m*/ * * @param publicKey * * @param text * * * @return Base64? */ public static String encrypt(PublicKey publicKey, String text) { Assert.notNull(publicKey); Assert.notNull(text); byte[] data = encrypt(publicKey, text.getBytes()); return data != null ? Base64.encodeBase64String(data) : null; }
From source file:flow.visibility.tapping.OpenDaylightHelper.java
/** The function for inserting the flow */ public static boolean installFlow(JSONObject postData, String user, String password, String baseURL) { StringBuffer result = new StringBuffer(); /** Check the connection to ODP REST API page */ try {/* w ww .java 2 s. com*/ if (!baseURL.contains("http")) { baseURL = "http://" + baseURL; } baseURL = baseURL + "/controller/nb/v2/flowprogrammer/default/node/OF/" + postData.getJSONObject("node").get("id") + "/staticFlow/" + postData.get("name"); /** Create URL = base URL + container */ URL url = new URL(baseURL); /** Create authentication string and encode it to Base64*/ String authStr = user + ":" + password; String encodedAuthStr = Base64.encodeBase64String(authStr.getBytes()); /** Create Http connection */ HttpURLConnection connection = (HttpURLConnection) url.openConnection(); /** Set connection properties */ connection.setRequestMethod("PUT"); connection.setRequestProperty("Authorization", "Basic " + encodedAuthStr); connection.setRequestProperty("Content-Type", "application/json"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); /** Set JSON Post Data */ OutputStream os = connection.getOutputStream(); os.write(postData.toString().getBytes()); os.close(); /** Get the response from connection's inputStream */ InputStream content = (InputStream) connection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(content)); String line = ""; while ((line = in.readLine()) != null) { result.append(line); } } catch (Exception e) { e.printStackTrace(); } /** checking the result of REST API connection */ if ("success".equalsIgnoreCase(result.toString())) { return true; } else { return false; } }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.feature.meta.AbstractSequenceMetaDataFeatureGenerator.java
public static String encodeToString(Object object) throws TextClassificationException { try {/*w ww . ja va 2s .co m*/ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); byteArrayOutputStream.close(); return Base64.encodeBase64String(byteArrayOutputStream.toByteArray()); } catch (IOException e) { throw new TextClassificationException(e); } }
From source file:com.liferay.sync.engine.util.Encryptor.java
protected static String getSalt() { byte[] saltBytes = new byte[_SALT_LENGTH]; _secureRandom.nextBytes(saltBytes);/*www. j a v a2 s . co m*/ return Base64.encodeBase64String(saltBytes).substring(0, _SALT_LENGTH); }
From source file:net.mc_cubed.msrp.MsrpUtil.java
/** * Generate a RFC 4975 Section 14.1 compliant SessionId for use in an MSRP * URI/* ww w.ja v a 2 s.c o m*/ * @return */ public static String generateMsrpUriSessionId() { SecureRandom secure = new SecureRandom(); byte[] bytes = new byte[MSRP_URI_SESSION_LENGTH]; secure.nextBytes(bytes); return Base64.encodeBase64String(bytes); }
From source file:com.app.framework.listeners.ApplicationListener.java
@Override public void contextInitialized(ServletContextEvent sce) { System.out.println("Hello. Application Started."); System.out.println("Working Dir: " + Application.getWorkingDir().getAbsolutePath()); String s = new String("mcg"); System.out.println("" + s); String md5 = MD5Utils.md5(s); System.out.println(md5);//w w w. j av a 2 s.co m SecretKey key = AESUtils.generateSecretKey(); byte[] keyBytes = AESUtils.getKeyBytes(key); key = AESUtils.getSecretKey(keyBytes); String encrypted = null; try { encrypted = Base64.encodeBase64String(AESUtils.encrypt(md5, key)); byte[] decrypted = AESUtils.decrypt(Base64.decodeBase64(encrypted.getBytes("utf-8")), key); System.out.println(encrypted); System.out.println(new String(decrypted)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:com.boulmier.machinelearning.jobexecutor.encrypted.AES.java
public String encrypt(String strToEncrypt) { try {/* w w w.ja va 2s . c o m*/ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); return (Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes("UTF-8")))); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) { System.out.println("Error while encrypting: " + e.toString()); } return null; }
From source file:de.schierla.jbeagle.BeagleBook.java
private String base64_encode(String text) { return Base64.encodeBase64String(text.getBytes(utf8)); }