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.buddycloud.friendfinder.HashUtils.java

public static String encodeSHA256(String provider, String contactId)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update((provider + ":" + contactId).getBytes("UTF-8"));
    byte[] digest = md.digest();
    return Base64.encodeBase64String(digest);
}

From source file:edu.kit.scc.cdmi.rest.CdmiObjectTest.java

@Test
public void testGetObjectByIdNotAuthorized() {
    String authString = Base64.encodeBase64String((restUser + "1:" + restPassword).getBytes());

    Response response = given().header("Authorization", "Basic " + authString).and()
            .header("Content-Type", "application/cdmi-object").when().get("/cdmi_objectid/invalid").then()
            .statusCode(org.apache.http.HttpStatus.SC_UNAUTHORIZED).extract().response();

    log.debug("Response {}", response.asString());
}

From source file:info.globalbus.dkim.DKIMUtil.java

protected static String base64Encode(byte[] b) {
    String encoded = Base64.encodeBase64String(b);
    // remove unnecessary linefeeds after 76 characters
    encoded = encoded.replace("\n", ""); // Linux+Win
    return encoded.replace("\r", ""); // Win --> FSTODO: select Encoder
    // without line termination
}

From source file:com.premiumminds.billy.portugal.services.certification.CertificationManager.java

public String getHashBase64(String source) throws InvalidHashException, InvalidKeyException {
    String hashBase64 = Base64.encodeBase64String(this.getHashBinary(source));
    if (this.autoVerifyHash) {
        if ((!this.verifyHashBase64(source, hashBase64))
                || (hashBase64.length() != CertificationManager.EXPECTED_HASH_LENGTH)) {
            throw new InvalidHashException();
        }/*from  w w w.j a v  a2  s.  com*/
    }
    return hashBase64;

}

From source file:io.druid.indexing.overlord.autoscaling.ec2.StringEC2UserData.java

@Override
public String getUserDataBase64() {
    final String finalData;
    if (versionReplacementString != null && version != null) {
        finalData = data.replace(versionReplacementString, version);
    } else {/*  www  . ja v a2 s  .  c  o  m*/
        finalData = data;
    }
    return Base64.encodeBase64String(StringUtils.toUtf8(finalData));
}

From source file:edu.kit.scc.cdmi.rest.CapabilitiesTest.java

@Test
public void testGetContainerCapabilities() {
    String authString = Base64.encodeBase64String((restUser + ":" + restPassword).getBytes());

    Response response = given().header("Authorization", "Basic " + authString).and()
            .header("Content-Type", "application/cdmi-capability").when().get("/cdmi_capabilities/container")
            .then().statusCode(org.apache.http.HttpStatus.SC_OK).extract().response();

    log.debug("Response {}", response.asString());
}

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

public static String objectToString(Object value) {
    if (value == null) {
        return "";
    } else if (value instanceof Date) {
        return String.valueOf(((Date) value).getTime());
    } else if (value instanceof Number || value instanceof String || value instanceof Boolean) {
        return value.toString();
    } else if (value instanceof Serializable) {
        return objectToBase64((Serializable) value);
    } else if (value instanceof BufferedImage) {
        return Base64.encodeBase64String(imageToByteArray((BufferedImage) value));
    } else {//from   w  w w .  j a v  a2  s . c o m
        return value.toString();
    }
}

From source file:com.quinsoft.zeidon.domains.Base64BlobDomain.java

@Override
public String convertToString(Task task, AttributeDef attributeDef, Object internalValue) {
    if (internalValue instanceof Blob) {
        Blob blob = (Blob) internalValue;
        return Base64.encodeBase64String(blob.getBytes());
    }// ww w. j  ava2 s .c o  m

    return super.convertToString(task, attributeDef, internalValue);
}

From source file:com.parasoft.em.client.impl.JSONClient.java

private HttpURLConnection getConnection(String restPath) throws IOException {
    URL url = new URL(baseUrl + restPath);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);//from   w  ww . jav a 2  s. c  o m
    connection.setRequestProperty("Accept", "application/json");
    if (username != null) {
        String encoding = username + ":" + password;
        encoding = Base64.encodeBase64String(encoding.getBytes("UTF-8"));
        connection.setRequestProperty("Authorization", "Basic " + encoding);
    }
    return connection;
}

From source file:com.trimble.tekla.teamcity.HttpConnector.java

public void PostPayload(TeamcityConfiguration conf, String url, String payload) {

    try {/*from  w  w  w  . j a  v a  2  s  .c  o  m*/

        String urlstr = conf.getUrl() + url;

        URL urldata = new URL(urlstr);
        logger.warn("Hook Request: " + urlstr);

        String authStr = conf.getUserName() + ":" + conf.getPassWord();
        String authEncoded = Base64.encodeBase64String(authStr.getBytes());

        HttpURLConnection connection = (HttpURLConnection) urldata.openConnection();

        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Authorization", "Basic " + authEncoded);

        if (payload != null) {
            connection.setRequestProperty("Content-Type", "application/xml; charset=utf-8");
            connection.setRequestProperty("Content-Length", Integer.toString(payload.length()));
            connection.getOutputStream().write(payload.getBytes("UTF8"));
        }

        InputStream content = (InputStream) connection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(content));

        StringBuilder dataout = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            dataout.append(line);
        }

        logger.warn("Hook Reply: " + line);

    } catch (Exception e) {
        logger.debug("Hook Exception: " + e.getMessage());
        e.printStackTrace();
    }
}