Example usage for org.apache.commons.codec.binary Base64 encodeBase64

List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 encodeBase64.

Prototype

public static byte[] encodeBase64(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm but does not chunk the output.

Usage

From source file:ezbake.data.graph.rexster.RexsterRestEzSecurityTokenIntegrationTest.java

/**
 * Builds the authorization header value.
 *
 * @param token The token to be inserted into the header.
 * @return A string that can be assigned to the {@link javax.ws.rs.core.HttpHeaders#AUTHORIZATION} header for making
 * rest requests on Rexster./*from w  w w .j a v  a 2 s  .c o  m*/
 * @throws org.apache.thrift.TException If an exception occurred while serializing the token.
 */
private static String getAuthorizationHeader(EzSecurityToken token) throws TException {
    final String tokenb64 = ThriftUtils.serializeToBase64(token);
    final byte[] bytes = Base64.encodeBase64((tokenb64 + ":nopass").getBytes());
    final String headerPart2 = new String(bytes);
    return "Basic " + headerPart2;
}

From source file:com.oakhole.utils.EncodeUtils.java

/**
 * Base64?.//from  ww  w.j av  a  2 s .c  om
 * 
 * @param input
 *            byte[]
 * @return String
 */
public static String base64Encode(byte[] input) throws UnsupportedEncodingException {
    return new String(Base64.encodeBase64(input), "UTF-8");
}

From source file:com.evolveum.midpoint.web.util.Base64Model.java

@Override
public void setObject(String object) {
    if (object == null) {
        model.setObject(null);// www  .  j a  v  a2  s.  c om
    }

    try {
        byte[] val = Base64.encodeBase64(object.getBytes("utf-8"));
        model.setObject(val);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.studio.server.model.AFileResource.java

public void setFile(File file) {
    this.file = file;
    if (file != null)
        try {/* w  w w  . jav a 2  s . c  o  m*/
            getValue().setData(Base64.encodeBase64(net.sf.jasperreports.eclipse.util.FileUtils.getBytes(file)));
            getValue().setHasData(true);
            return;
        } catch (IOException e) {
            e.printStackTrace();
        }
    getValue().setData(null);
    getValue().setHasData(false);
}

From source file:com.yahoo.yos.RequestToken.java

public Cookie getCookie() throws UnsupportedEncodingException, JSONException {
    return new Cookie("yosdk_rt",
            new String(Base64.encodeBase64(toJSONObject().toString().getBytes("UTF-8")), "UTF-8"));
}

From source file:com.photon.phresco.service.rest.api.LoginServiceTest.java

public void testLogin() throws PhrescoException {
    String userName = "kumar_s";
    String password = "Phresco@123";
    byte[] encodeBase64 = Base64.encodeBase64(password.getBytes());
    String encodedPassword = new String(encodeBase64);
    PhrescoServerFactory.initialize();/*from  w w w.  jav a  2  s.  co m*/
    RepositoryManager repoMgr = PhrescoServerFactory.getRepositoryManager();
    Credentials credentials = new Credentials(userName, encodedPassword);
    Client client = ClientHelper.createClient();
    WebResource resource = client.resource(repoMgr.getAuthServiceURL() + "/ldap/authenticate");
    resource.accept(MediaType.APPLICATION_JSON);
    ClientResponse response = resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, credentials);
    GenericType<User> genericType = new GenericType<User>() {
    };
    User user = response.getEntity(genericType);
    Assert.assertEquals(true, user.isPhrescoEnabled());
}

From source file:edu.kit.scc.test.rest.AuthorizationTest.java

@Test
public void testBasicAuthorization() {
    String auth = restUser + ":" + restPassword;
    byte[] authZheader = auth.getBytes();
    String authorizationHeader = "Basic "
            + new String(Base64.encodeBase64(authZheader), StandardCharsets.UTF_8);

    assertTrue(controller.verifyAuthorization(authorizationHeader));
}

From source file:io.zipi.common.util.AesEncrypter.java

/**
 * Encrypt./*w w  w .j  a v  a 2 s  .  c  o m*/
 * @param plainText the plain text
 * @param secretKey the secret key
 * @return the string
 */
public static String encrypt(String secretKey, String plainText) {
    if (plainText == null) {
        return null;
    }
    byte[] encrypted;
    Cipher cipher;
    try {
        SecretKeySpec skeySpec = keySpecFromSecretKey(secretKey);

        cipher = Cipher.getInstance("AES"); //$NON-NLS-1$
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
    try {
        encrypted = cipher.doFinal(plainText.getBytes());
    } catch (IllegalBlockSizeException | BadPaddingException e) {
        throw new RuntimeException(e);
    }
    return "$CRYPT::" + new String(Base64.encodeBase64(encrypted)); //$NON-NLS-1$
}

From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java

public static String objectToBase64(Serializable o) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos)) {
        oos.writeObject(o);//from  w  w w  .  j a  v a  2  s . c o  m
        return new String(Base64.encodeBase64(baos.toByteArray()));
    } catch (IOException e) {
        return null;
    }
}

From source file:net.mooncloud.hadoop.hive.ql.udf.UDFBase64.java

public Text evaluate(BytesWritable b) {
    if (b == null) {
        return null;
    }//  w  w  w .  j  a  va 2  s .c  o m
    byte[] bytes = new byte[b.getLength()];
    System.arraycopy(b.getBytes(), 0, bytes, 0, b.getLength());
    result.set(Base64.encodeBase64(bytes));
    return result;
}