List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.cloudbees.eclipse.core.util.Utils.java
/** * Converts string to US-ASCII base64 string. * //from ww w . java 2s. co m * @param str * @return */ public static String toB64(final String str) { try { if (str == null || str.length() == 0) { return new String(new byte[0], "US-ASCII"); } return new String(Base64.encodeBase64(str.getBytes("UTF-8")), "US-ASCII"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:hudson.remoting.BinarySafeStreamTest.java
public void testSingleWrite() throws IOException { byte[] ds = getDataSet(65536); String master = new String(Base64.encodeBase64(ds)); ByteArrayOutputStream buf = new ByteArrayOutputStream(); OutputStream o = BinarySafeStream.wrap(buf); o.write(ds, 0, ds.length);//from ww w.j av a 2 s .c om o.close(); assertEquals(buf.toString(), master); }
From source file:com.liferay.portal.spring.remoting.AuthenticatingHttpInvokerRequestExecutor.java
/** * Called every time a HTTP invocation is made. This implementation allows * the parent to setup the connection, and then adds an * <code>Authorization</code> HTTP header property for BASIC authentication. */// ww w . j a va2 s .co m @Override protected void prepareConnection(HttpURLConnection con, int contentLength) throws IOException { super.prepareConnection(con, contentLength); if (getUserId() > 0) { String password = GetterUtil.getString(getPassword()); String base64 = getUserId() + StringPool.COLON + password; con.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(base64.getBytes()))); } }
From source file:de.unigoettingen.sub.commons.util.stream.StreamUtils.java
/************************************************************************************ * get MimeType as {@link String} from given URL including proxy details * //w w w . j a va2 s . c o m * @param url the url from where to get the MimeType * @param httpproxyhost host of proxy * @param httpproxyport port of proxy * @param httpproxyusername username for proxy * @param httpproxypassword password for proxy * @return MimeType as {@link String} * @throws IOException ************************************************************************************/ public static String getMimeTypeFromUrl(URL url, String httpproxyhost, String httpproxyport, String httpproxyusername, String httpproxypassword) throws IOException { if (httpproxyhost != null) { Properties properties = System.getProperties(); properties.put("http.proxyHost", httpproxyhost); if (httpproxyport != null) { properties.put("http.proxyPort", httpproxyport); } else { properties.put("http.proxyPort", "80"); } } URLConnection con = url.openConnection(); if (httpproxyusername != null) { String login = httpproxyusername + ":" + httpproxypassword; String encodedLogin = new String(Base64.encodeBase64(login.getBytes())); con.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin); } return con.getContentType(); }
From source file:com.dynamobi.ws.util.LucidDBEncoder.java
public String encodePassword(String rawPass, Object salt) { // support a case: password is null. if (rawPass.isEmpty()) { return ""; }//from www . j av a 2 s. co m String saltedPass = mergePasswordAndSalt(rawPass, salt, false); MessageDigest messageDigest = getMessageDigest(); byte[] digest; try { digest = messageDigest.digest(saltedPass.getBytes("UTF-16LE")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-16LE not supported!"); } // System.out.println("ZZZZ Base64 [" // + new String(Base64.encodeBase64(digest)) + "] Hex = [" // + new String(Hex.encodeHex(digest)) + "]"); if (getEncodeHashAsBase64()) { return new String(Base64.encodeBase64(digest)); } else { return new String(Hex.encodeHex(digest)); } }
From source file:com.predic8.membrane.core.transport.http.client.ProxyConfiguration.java
/** * The "Basic" authentication scheme defined in RFC 2617 does not properly define how to treat non-ASCII characters. */// w ww .j av a 2s. com public String getCredentials() { StringBuilder buffer = new StringBuilder(); buffer.append("Basic "); byte[] base64UserPass = Base64.encodeBase64((username + ":" + password).getBytes(Constants.UTF_8_CHARSET)); buffer.append(new String(base64UserPass, Constants.UTF_8_CHARSET)); return buffer.toString(); }
From source file:com.cloud.utils.rest.BasicEncodedRESTValidationStrategy.java
private String encodeCredentials() { final String authString = user + ":" + password; final byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); final String authStringEnc = new String(authEncBytes); return authStringEnc; }
From source file:com.att.api.immn.controller.GetMsgContentController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); final String msgId = request.getParameter("contentMsgId"); final String partNumb = request.getParameter("contentPartNumber"); JSONObject jresponse = new JSONObject(); try {/*w w w. j a v a 2 s . co m*/ final MessageContent msgContent = srvc.getMessageContent(msgId, partNumb); jresponse.put("success", true); final String type = msgContent.getContentType().toLowerCase(); /* TODO: handle unknown type */ if (type.contains("text")) { jresponse.put("text", "Message Content: " + new String(msgContent.getContent())); } else if (type.contains("image")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("image", image); } else if (type.contains("video")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("video", image); } else if (type.contains("audio")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("audio", image); } } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:gobblin.aws.GobblinAWSUtils.java
/*** * Encodes String data using the base64 algorithm and does not chunk the output. * * @param data String to be encoded./* ww w.jav a 2 s .co m*/ * @return Encoded String. */ @FindbugsSuppressWarnings("DM_DEFAULT_ENCODING") public static String encodeBase64(String data) { final byte[] encodedBytes = Base64.encodeBase64(data.getBytes()); return new String(encodedBytes); }
From source file:com.adyen.Util.HMACValidator.java
public String calculateHMAC(String data, String key) throws java.security.SignatureException { try {/* w ww .ja v a2s . co m*/ byte[] rawKey = Hex.decodeHex(key.toCharArray()); // Create an hmac_sha256 key from the raw key bytes SecretKeySpec signingKey = new SecretKeySpec(rawKey, HMAC_SHA256_ALGORITHM); // Get an hmac_sha256 Mac instance and initialize with the signing // key Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM); mac.init(signingKey); // Compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(data.getBytes(C_UTF8)); // Base64-encode the hmac return new String(Base64.encodeBase64(rawHmac)); } catch (Exception e) { throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } }