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

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

Introduction

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

Prototype

public static String encodeBase64String(final byte[] binaryData) 

Source Link

Document

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

Usage

From source file:com.alliander.osgp.webdevicesimulator.domain.entities.OslpLogItem.java

public OslpLogItem(final byte[] deviceUid, final String deviceIdentification, final boolean incoming,
        final Message message) {
    this.deviceUid = Base64.encodeBase64String(deviceUid);
    this.deviceIdentification = deviceIdentification;
    this.incoming = incoming;

    // Truncate the logitems to length
    this.encodedMessage = StringUtils.substring(OslpLogItem.bytesToCArray(message.toByteArray()), 0,
            MAX_MESSAGE_LENGTH);/*from   w w  w . j a  v a  2  s  .  com*/
    this.decodedMessage = StringUtils.substring(message.toString(), 0, MAX_MESSAGE_LENGTH);
}

From source file:com.mothsoft.alexis.web.CurrentUser.java

public String getApiBasicAuthorizationHeaderValue() {
    final byte[] bytes = new String(getUsername() + ":" + getApiToken()).getBytes(Charset.forName("UTF-8"));
    return "Basic " + Base64.encodeBase64String(bytes);
}

From source file:guru.nidi.ramltester.loader.BasicAuthUrlRamlLoader.java

public BasicAuthUrlRamlLoader(String baseUrl, final String username, final String password,
        CloseableHttpClient httpClient) {
    super(baseUrl, new SimpleUrlFetcher() {
        @Override/*w w  w. j a va  2 s.  c  om*/
        protected HttpGet postProcessGet(HttpGet get) {
            get.addHeader("Authorization", encode(username, password));
            return get;
        }

        private String encode(String username, String password) {
            return Base64.encodeBase64String(
                    ("Basic " + username + ":" + password).getBytes(Charset.forName("iso-8859-1")));
        }
    }, httpClient);
}

From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java

public String sha256Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha256(Base64.decodeBase64(dataB64)));
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.GetPluginSettingsIconExecutor.java

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content-type", "image/png");
    jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes("/docker-swarm.png")));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));// w w w. j a  va 2 s.  c o m
    return defaultGoPluginApiResponse;

}

From source file:magicware.scm.redmine.tools.ConfigFacadeTestCase.java

@Test
public void testGetSampleJson() {

    Config config = new Config();
    config.setRedmineHost("192.168.0.10");
    config.setRedminePort(80);/*  w  w w.j ava2  s  .c  o  m*/
    config.setRedmineContext("/redmine");
    config.setRedmineAuthUser("redmine");
    config.setRedmineAuthPwd(Base64.encodeBase64String("dummy".getBytes()));

    SyncItem[] syncItems = new SyncItem[1];
    syncItems[0] = new SyncItem();
    syncItems[0].setFilePath("D:\\QA.xls");
    syncItems[0].setSheetName("????");
    syncItems[0].setJsonTemplate("D:/issue_template_001.json");
    syncItems[0].setProjectId("8");
    syncItems[0].setKeyFiledId("cf_16");
    syncItems[0].setKeyColumnIdx(1);

    config.setSyncItems(syncItems);
    log.info("sample config json string");
    log.info(JSON.encode(config, true));
}

From source file:com.springcryptoutils.core.mac.Base64EncodedMacImplSpecificProviderTest.java

@Test
public void testDigest() throws Exception {
    assertNotNull("mac", mac);
    final String message = Base64.encodeBase64String("Hello".getBytes());
    final String digest = mac.digest(message);
    assertNotNull("digest", digest);
    assertTrue("digest.length() > 0", digest.length() > 0);
    final String digest2 = mac.digest(message);
    assertNotNull("digest2", digest);
    assertTrue("digest2.length() > 0", digest.length() > 0);
    assertEquals("digests", digest, digest2);
}

From source file:fi.metatavu.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 va  2 s.  c om
        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.twitter.hbc.httpclient.auth.BasicAuth.java

public String getAuthToken() {
    return Base64.encodeBase64String((this.username + ":" + this.password).getBytes());
}

From source file:com.elle.analyster.admissions.AESCrypt.java

public static String encrypt(String key, String initVector, String value) {
    try {//from   w ww.  ja v  a  2s . co m
        IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
        SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);

        byte[] encrypted = cipher.doFinal(value.getBytes());
        System.out.println("encrypted string: " + Base64.encodeBase64String(encrypted));

        return Base64.encodeBase64String(encrypted);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return null;
}