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:net.duckling.ddl.util.Utility.java

public static String getBASE64(String s) {
    if (s == null) {
        return null;
    }//from  w  w w.  j  ava2 s.co m
    return new String(Base64.encodeBase64(s.getBytes()));
}

From source file:com.formatAdmin.utils.UtilsSecurity.java

public static String cifrarMD5(String texto) {
    String base64EncryptedString = "";
    try {/*from   ww  w .  j a v a 2 s  . c  o  m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(SECRET_MD5_KEY.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);

        SecretKey key = new SecretKeySpec(keyBytes, ENCRYPT_ALGORITHM);
        Cipher cipher = Cipher.getInstance(ENCRYPT_ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, key);

        byte[] plainTextBytes = texto.getBytes("utf-8");
        byte[] buf = cipher.doFinal(plainTextBytes);
        byte[] base64Bytes = Base64.encodeBase64(buf);
        base64EncryptedString = new String(base64Bytes);

    } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException | BadPaddingException
            | IllegalBlockSizeException | NoSuchPaddingException ex) {
    }
    return base64EncryptedString;
}

From source file:com.barrybecker4.common.util.Base64Codec.java

/**
 * take a String and compress it./*  w  w  w  .  j a  v a  2 s .c  o m*/
 * See @decompress for reversing the compression.
 * @param data a string to compress.
 * @return compressed string representation.
 */
public static synchronized String compress(final String data) {

    ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512);
    Deflater deflater = new Deflater();
    DeflaterOutputStream oStream = new DeflaterOutputStream(byteOut, deflater);

    try {
        oStream.write(data.getBytes(CONVERTER_UTF8));
        oStream.flush();
        oStream.close();
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported encoding exception :" + e.getMessage(), e);
    } catch (IOException e) {
        throw new IllegalStateException("io error :" + e.getMessage(), e);
    }

    return new String(Base64.encodeBase64(byteOut.toByteArray()));
}

From source file:com.koda.common.lcm.Tool.java

private static String doStuff(byte[] buffer) {
    // reverse bytes
    int lastIndex = buffer.length - 1;
    for (int i = 0; i < buffer.length / 2; i++) {
        byte tmp = buffer[i];
        buffer[i] = (byte) (buffer[lastIndex - i] ^ xorValue);
        buffer[lastIndex - i] = (byte) (tmp ^ xorValue);
    }/*from ww w .j a  va2s .co m*/

    return new String(Base64.encodeBase64(buffer));
}

From source file:com.photon.phresco.framework.impl.BaseTest.java

@BeforeClass
public static void setUpBeforeClass() throws PhrescoException {
    //String serviceURL = "http://172.16.25.196:3030/service/rest/api";
    String serviceURL = "http://172.16.25.44:8081/service/rest/api";
    String userName = "phresco";
    byte[] encodeBase64 = Base64.encodeBase64("U83EfU$r".getBytes());
    String password = new String(encodeBase64);
    ServiceContext context = new ServiceContext();
    context.put("phresco.service.url", serviceURL);
    context.put("phresco.service.username", userName);
    context.put("phresco.service.password", password);
    serviceManager = ServiceClientFactory.getServiceManager(context);
    System.out.println("BaseTest serviceManager : " + serviceManager.getCustomers().size());
}

From source file:edu.lternet.pasta.client.HttpGetFactory.java

/**
 * Manufactures an HttpGet object, adding auth-token and robot cookies as appropriate.
 * /*w ww .  j  a  va 2 s.  c  o  m*/
 * @param url       The URL of the request
 * @param token     Auth-token string, possibly null
 * @param robot     Robot string, possibly null
 * @return          An Httpget object
 */
public static HttpGet makeHttpGet(String url, String token, String robot) {
    HttpGet httpGet = new HttpGet(url);
    if (token != null) {
        httpGet.setHeader("Cookie", "auth-token=" + token);
    }
    if (robot != null) {
        String b64Robot = new String(Base64.encodeBase64(robot.getBytes()));
        httpGet.setHeader("Cookie", "robot=" + b64Robot);
    }

    return httpGet;
}

From source file:com.hatta.consumer.App.java

private static HttpHeaders getHeadersWithClientCredentials() {
    String plainClientCredentials = "frontend:secret";
    String base64ClientCredentials;
    base64ClientCredentials = new String(Base64.encodeBase64(plainClientCredentials.getBytes()));

    HttpHeaders headers = getHeaders();/*from w  w  w .  j  a v a 2s .  co  m*/
    headers.add("Authorization", "Basic " + base64ClientCredentials);
    return headers;
}

From source file:com.zxy.commons.codec.utils.Base64Utils.java

/**
 * ?//from w  w  w . j ava2 s  . c  om
 * 
 * @param source ??
 * @param charset 
 * @return ??
 */
public static String encode(String source, String charset) {
    if (StringUtils.isBlank(source)) {
        return null;
    }
    return new String(Base64.encodeBase64(source.getBytes(Charset.forName(charset))));
}

From source file:com.comichentai.serialize.SerializeUtil.java

public static String encodeObject(Object obj) {
    byte[] bytes = serialize(obj);
    byte[] zipped = CompressUtil.zip(bytes);
    return new String(Base64.encodeBase64(zipped));
}

From source file:com.esri.geoevent.datastore.Crypto.java

static public String doEncrypt(String stringToEncrypt) throws GeneralSecurityException {
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.ENCRYPT_MODE, encryptionKey);
    byte[] encVal = c.doFinal(stringToEncrypt.getBytes());
    String encodedEncryptedString = new String(Base64.encodeBase64(encVal));
    return encodedEncryptedString;
}