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:io.apiman.common.util.Basic.java

public static String encode(String username, String password) {
    String up = username + ':' + password;
    StringBuilder builder = new StringBuilder();
    builder.append("Basic ");
    builder.append(Base64.encodeBase64String(up.getBytes()));
    return builder.toString();
}

From source file:com.bytecode.util.Crypto.java

public static String encrypt128(String key, String message) throws Exception {
    return Base64.encodeBase64String(encrypt(key, message, BITS128));
}

From source file:guru.nidi.atlassian.remote.HttpUtils.java

public static void setAuthHeader(HttpRequestBase req, String username, String password) {
    req.setHeader("Authorization", "Basic "
            + Base64.encodeBase64String((username + ":" + password).getBytes(Charset.forName("utf-8"))));
}

From source file:com.threerings.getdown.util.ConnectionUtil.java

/**
 * Opens a connection to a URL, setting the authentication header if user info is present.
 *//*from w  w  w .j  a  va  2 s . c  o m*/
public static URLConnection open(URL url) throws IOException {
    URLConnection conn = url.openConnection();

    // If URL has a username:password@ before hostname, use HTTP basic auth
    String userInfo = url.getUserInfo();
    if (userInfo != null) {
        // Remove any percent-encoding in the username/password
        userInfo = URLDecoder.decode(userInfo, "UTF-8");
        // Now base64 encode the auth info and make it a single line
        String encoded = Base64.encodeBase64String(userInfo.getBytes("UTF-8")).replaceAll("\\n", "")
                .replaceAll("\\r", "");
        conn.setRequestProperty("Authorization", "Basic " + encoded);
    }

    return conn;
}

From source file:com.amazon.ion.plugin.intellij.helpers.ContentCorrectnessHelper.java

/**
 * Validate Base64 value for BLOB data type
 *
 * @param text Input value//  www.j  a v a 2  s.c  o m
 * @return true if the value is a valid base64 encoded blob
 */
public static boolean isValidBase64(CharSequence text) {
    final String input = text.toString();
    final String decoded = new String(Base64.decodeBase64(input));
    final String encoded = Base64.encodeBase64String(decoded.getBytes());
    return encoded.equals(input);
}

From source file:de.pawlidi.openaletheia.utils.Converter.java

public static String toString(byte[] array) {
    return Base64.encodeBase64String(array);
}

From source file:com.inflight.util.Password.java

/** Computes a salted PBKDF2 hash of given plaintext password
suitable for storing in a database. // ww  w. j  a  v  a  2  s  .  co m
Empty passwords are not supported. */
public static String getSaltedHash(String password) throws Exception {
    byte[] salt = SecureRandom.getInstance("SHA1PRNG").generateSeed(saltLen);
    //        System.out.println(salt.toString());
    //        // store the salt with the password

    System.out.println(Base64.encodeBase64String(salt) + "$" + hash(password, salt));
    return Base64.encodeBase64String(salt) + "$" + hash(password, salt);
    //return "5Py5AAS9QlaRhtm0Ac3FNeyfuTU4oNpYKDCig4vtwS8=$1KQIRHF5zXULP/yoOr9lXHlOWyUjq/Q0A+5Caap9WA8=";
}

From source file:Main.java

public static void setServiceDataIntoEnv(String serviceName, ByteBuffer metaData, Map<String, String> env) {
    byte[] byteData = metaData.array();
    env.put(getPrefixServiceName(serviceName), Base64.encodeBase64String(byteData));
}

From source file:com.bjwg.back.util.EncodeUtils.java

public static String encodeBase64(byte[] input) {
    return Base64.encodeBase64String(input);
}

From source file:EncDec.AES.java

public static String encrypt(String key, String initVector, String value) {
    try {//from ww  w .j  a  v a 2s  .c  o 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;
}