List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:corner.orm.tapestry.utils.ComponentResponseUtils.java
private static String processFileName(String fileName, String agent) throws IOException { String codedfilename = fileName; if (null != agent && -1 != agent.indexOf("MSIE")) {// IE //apachecodeC?: //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6437829 URLCodec codec = new URLCodec("UTF-8"); try {//from w ww.j a v a 2s . co m codedfilename = codec.encode(fileName); } catch (EncoderException e) { log.warn(e); } } else if (null != agent && -1 != agent.indexOf("Mozilla")) { // Mozilla // firefox codedfilename = String.format(MOZILLA_DOWNLOAD_FILE_NAME, new String(Base64.encodeBase64(fileName.getBytes("UTF-8")))); } return codedfilename; }
From source file:com.alibaba.citrus.service.requestcontext.session.idgen.random.impl.RandomIDGenerator.java
public String generateSessionID() { assertInitialized();// w w w . j av a 2 s . c o m byte[] bytes = new byte[(length + 3) / 4 * 3]; rnd.nextBytes(bytes); byte[] b64Encoded = Base64.encodeBase64(bytes); StringBuilder buf = new StringBuilder(length); for (int i = 0; i < length; i++) { char ch = (char) b64Encoded[i]; // ?/+url switch (ch) { case '/': ch = '$'; break; case '+': ch = '-'; break; case '=': unreachableCode(); } buf.append(ch); } return buf.toString(); }
From source file:com.mqtt.curl.mqtt.util.Base64Util.java
/** * ??BASE64// w w w.ja va 2 s . c om * * @param binaryData * @return */ public static String encode(byte[] binaryData) { try { return new String(Base64.encodeBase64(binaryData), "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } }
From source file:edu.internet2.middleware.openid.message.impl.AssociationRequestMarshaller.java
/** {@inheritDoc} */ protected void marshallParameters(AssociationRequest request, ParameterMap parameters) { parameters.put(Parameter.assoc_type.QNAME, request.getAssociationType().toString()); SessionType sessionType = request.getSessionType(); parameters.put(Parameter.session_type.QNAME, sessionType.toString()); if (sessionType.equals(SessionType.DH_SHA1) || sessionType.equals(SessionType.DH_SHA256)) { DHParameterSpec dhParameters = request.getDHParameters(); if (dhParameters != null) { byte[] modulus = Base64.encodeBase64(dhParameters.getP().toByteArray()); parameters.put(Parameter.dh_modulus.QNAME, new String(modulus)); byte[] gen = Base64.encodeBase64(dhParameters.getG().toByteArray()); parameters.put(Parameter.dh_gen.QNAME, new String(gen)); }/*from w w w .j a v a2 s. c o m*/ DHPublicKey consumerPublic = request.getDHConsumerPublic(); if (consumerPublic != null) { String publicKey = EncodingUtils.encodePublicKey(consumerPublic); parameters.put(Parameter.dh_consumer_public.QNAME, publicKey); } } }
From source file:davmail.util.IOUtil.java
/** * Base64 encode value./* w w w. j a v a 2 s. co m*/ * * @param value input value * @return base64 value * @throws IOException on error */ public static String encodeBase64AsString(byte[] value) throws IOException { return new String(Base64.encodeBase64(value), "ASCII"); }
From source file:com.emc.atmos.api.test.EsuApiJerseyAdapterTest.java
/** * Test handling signature failures. Should throw an exception with * error code 1032.// w ww. ja v a 2 s .co m */ @Test public void testSignatureFailure() throws Exception { byte[] goodSecret = config.getSecretKey(); String secretStr = new String(Base64.encodeBase64(goodSecret), "UTF-8"); byte[] badSecret = Base64.decodeBase64(secretStr.toUpperCase().getBytes("UTF-8")); try { // Fiddle with the secret key config.setSecretKey(badSecret); testCreateEmptyObject(); Assert.fail("Expected exception to be thrown"); } catch (EsuException e) { Assert.assertEquals("Expected error code 1032 for signature failure", 1032, e.getAtmosCode()); } finally { config.setSecretKey(goodSecret); } }
From source file:info.magnolia.testframework.util.TestUtil.java
/** * A static method to open an URL connection. Yes we have similar functionality in * {@link info.magnolia.testframework.htmlunit.AbstractMagnoliaHtmlUnitTest} but those methods are not static. * In order to use {@link org.junit.BeforeClass} and {@link org.junit.AfterClass} (i.e. so that the setup is only * triggered once for all tests of a class) we need to use static methods. *//*from ww w . ja va2 s .c o m*/ public static Page openJcrPropServlet(String url, AbstractMagnoliaIntegrationTest.User user) throws IOException { final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); final WebConnection connection = new DebuggingWebConnection(webClient.getWebConnection(), String.valueOf(System.currentTimeMillis())); webClient.setWebConnection(connection); final String authString = user + ":" + user; final String encodedAuthStr = new String(Base64.encodeBase64(authString.getBytes())); webClient.addRequestHeader("Authorization", "Basic " + encodedAuthStr); return webClient.getPage(new URL(url)); }
From source file:com.hi3project.dandelion.util.properties.ImageProperty.java
private String encondeImage(byte[] imageData) { return new String(Base64.encodeBase64(imageData)); }
From source file:core.TestConfig.java
public static String encodeAuth(String s) { return "Basic " + new String(Base64.encodeBase64(s.getBytes())); }
From source file:com.hobba.hobaserver.services.security.TokenUtil.java
public String getToken(String kid, String expiration_time) { HobaKeysFacadeREST hkfrest = new HobaKeysFacadeREST(); HobaKeys hk = hkfrest.findHKIDbyKID(kid); HobaDevices hd = hk.getIdDevices();/*from ww w . java2 s . c o m*/ HobaUser hu = hd.getIduser(); SecureRandom random = new SecureRandom(); String rand = new BigInteger(256, random).toString(32); HobaToken ht = new HobaToken(); ht.setToken(rand); long time = 0; try { time = Long.parseLong(expiration_time); if (time > 0) { Date date = new Date(new Date().getTime() + (time * 1000)); ht.setExpiration(date); } else { ht.setExpiration(null); } } catch (Exception e) { ht.setExpiration(null); } ht.setIsValid(Boolean.TRUE); ht.setIdUser(hu); HobaTokenFacadeREST htfrest = new HobaTokenFacadeREST(); ht = htfrest.create(ht); String token = kid + ":" + rand; byte[] encodedBytes = Base64.encodeBase64(token.getBytes()); token = new String(encodedBytes); return token; }