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.qpark.eip.core.spring.security.https.EipHttpsClientHttpRequestFactory.java

/**
 * Initialize the HTTPs connection./*w w w  .  ja v  a2  s.  com*/
 *
 * @throws UnsupportedEncodingException
 */
@PostConstruct
public void init() throws UnsupportedEncodingException {
    if (this.userName != null) {
        if (this.password == null) {
            this.password = "";
        }
        this.base64UserNamePassword = new String(Base64.encodeBase64String(
                new StringBuffer(this.userName).append(":").append(this.password).toString().getBytes("UTF-8")))
                        .replaceAll("\n", "");
    }
}

From source file:edu.wpi.cs.wpisuitetng.authentication.BasicAuth.java

/**
 * Static utility for generating a BasicAuth token.
 *       Format: "Authorization: Basic " + [Base64Encoded]username:password
 * @param username//w ww  .j a  va2  s.  co  m
 * @param pass
 * @return   a String containing a BasicAuth token for the given parameters.
 */
public static String generateBasicAuth(String username, String pass) {
    String authToken = "Basic ";
    String credentials = username + ":" + pass;

    authToken += Base64.encodeBase64String(credentials.getBytes());

    return authToken;
}

From source file:com.chromelogger.java.ChromeLogger.java

public Map.Entry<String, String> getHeader(boolean flush) {

    JSONObject jo = new JSONObject(this.data);
    byte[] jsonString;

    try {/*  www  . j a  va 2s .com*/
        jsonString = jo.toString().getBytes("UTF-8");
        Map.Entry<String, String> retVal = new AbstractMap.SimpleEntry<String, String>(HEADER,
                Base64.encodeBase64String(jsonString));

        if (flush) {

            reset();
        }
        return retVal;

    } catch (Exception e) {

        e.printStackTrace();
    }
    return null;
}

From source file:com.microsoft.azure.batch.auth.BatchCredentialsInterceptor.java

private String sign(String accessKey, String stringToSign) {
    try {/*from  w  ww .  j ava2s  . c  o  m*/
        // Encoding the Signature
        // Signature=Base64(HMAC-SHA256(UTF8(StringToSign)))
        Mac hmac = Mac.getInstance("hmacSHA256");
        hmac.init(new SecretKeySpec(Base64.decodeBase64(accessKey), "hmacSHA256"));
        byte[] digest = hmac.doFinal(stringToSign.getBytes("UTF-8"));
        return Base64.encodeBase64String(digest);
    } catch (Exception e) {
        throw new IllegalArgumentException("accessKey", e);
    }
}

From source file:com.streamsets.datacollector.updatechecker.UpdateChecker.java

static String getSha256(String id) {
    try {//www.  j  a  va  2s. co m
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(id.getBytes("UTF-8"));
        return Base64.encodeBase64String(md.digest());
    } catch (Exception ex) {
        return "<UNKNOWN>";
    }
}

From source file:com.splicemachine.derby.stream.output.PipelineWriterBuilder.java

public String getHTableWriterBuilderBase64String() throws IOException, StandardException {
    return Base64.encodeBase64String(SerializationUtils.serialize(this));
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.http.HttpArtifactCredentials.java

public HttpArtifactCredentials(HttpArtifactAccount account, OkHttpClient okHttpClient) {
    this.name = account.getName();
    this.okHttpClient = okHttpClient;
    Builder builder = new Request.Builder();
    boolean useLogin = !StringUtils.isEmpty(account.getUsername())
            && !StringUtils.isEmpty(account.getPassword());
    boolean useUsernamePasswordFile = !StringUtils.isEmpty(account.getUsernamePasswordFile());
    boolean useAuth = useLogin || useUsernamePasswordFile;
    if (useAuth) {
        String authHeader = "";
        if (useUsernamePasswordFile) {
            authHeader = "Basic " + Base64
                    .encodeBase64String((credentialsFromFile(account.getUsernamePasswordFile())).getBytes());
        } else if (useLogin) {
            authHeader = "Basic " + Base64
                    .encodeBase64String((account.getUsername() + ":" + account.getPassword()).getBytes());
        }//from  w ww.  j  a v a  2s  .  c  om
        builder.header("Authorization", authHeader);
        log.info("Loaded credentials for http artifact account {}", account.getName());
    } else {
        log.info("No credentials included with http artifact account {}", account.getName());
    }
    requestBuilder = builder;
}

From source file:dashboard.Mixpanel.java

public int postCDNEventToMixpanel(String API_KEY, String TOKEN, String ip, String eventName, String eventTime,
        String method, String fileName, String fName, String userAgent, String statusCode, String registrant)
        throws IOException {

    try {//from  w  w  w. j  a  v a  2  s .c  om
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(eventTime);
        long timeInSecSinceEpoch = date.getTime();
        if (timeInSecSinceEpoch > 0)
            timeInSecSinceEpoch = timeInSecSinceEpoch / 1000;

        JSONObject obj1 = new JSONObject();
        obj1.put("distinct_id", ip);
        obj1.put("ip", ip);
        obj1.put("File path", fileName);
        obj1.put("File name", fName);
        obj1.put("User agent", userAgent);
        obj1.put("Status code", statusCode);
        obj1.put("Method", method);
        obj1.put("Registrant", registrant);
        obj1.put("time", timeInSecSinceEpoch);
        obj1.put("token", TOKEN);

        JSONObject obj2 = new JSONObject();
        obj2.put("event", eventName);
        obj2.put("properties", obj1);

        String s2 = obj2.toString();
        String encodedJSON = Base64.encodeBase64String(StringUtils.getBytesUtf8(s2));

        return postRequest(encodedJSON, API_KEY);
    } catch (Exception e) {
        //throw new RuntimeException("Can't POST to Mixpanel.", e);
        e.printStackTrace();
        return 0;
    }

}

From source file:de.qaware.campus.secpro.web.passwords.SecurePasswords.java

@PostConstruct
public void initialize() {
    String saltBase64 = Base64.encodeBase64String(new byte[] { 's', 'a', 'l', 't' });
    salt = Salt.fromBase64(saltBase64);/*from   w  w  w.ja v  a2  s. c  o  m*/
}

From source file:com.cisco.ca.cstg.pdi.services.license.LicenseCryptoServiceImpl.java

public void encryptToFile() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
        IllegalBlockSizeException, BadPaddingException, IOException {
    BufferedWriter out = null;/* w  w  w .ja  va 2  s  . com*/
    try {
        byte[] raw = getPassword().getBytes(Charset.forName(Constants.UTF8));
        SecretKeySpec skeySpec = new SecretKeySpec(raw, ALGORITHM_BLOWFISH);
        Cipher cipher = null;
        cipher = Cipher.getInstance(ALGORITHM_BLOWFISH);
        cipher.init(1, skeySpec);
        byte[] output = cipher.doFinal(getMetaData().getBytes());
        BigInteger n = new BigInteger(output);

        String b64hidden = Base64.encodeBase64String(n.toString(16).getBytes());
        setAssessmentKey(b64hidden);

        out = new BufferedWriter(new FileWriter(this.getAssessmentKeyFileName()));
        out.write(b64hidden);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}