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.emc.atmos.api.jersey.ProxyAuthFilter.java

protected void handleProxyAuth(ClientRequest request) {
    if (proxyUser != null && proxyUser.length() > 0) {
        String userPass = proxyUser + ":" + ((proxyPassword == null) ? "null" : proxyPassword);

        String userPass64;// w ww .  ja  v  a  2s .c  om
        try {
            userPass64 = Base64.encodeBase64String(userPass.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            userPass64 = Base64.encodeBase64String(userPass.getBytes());
        }

        // Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459815
        userPass64 = userPass64.replaceAll("\n", "");

        request.getHeaders().putSingle("Proxy-Authorization", "Basic " + userPass64);
    }
}

From source file:com.github.aistomin.jenkins.real.UsernamePasswordCredentials.java

@Override
public Map<String, String> headers() throws Exception {
    final Map<String, String> map = new ConcurrentHashMap<>();
    map.put("Authorization", String.format("Basic %s",
            Base64.encodeBase64String(String.format("%s:%s", this.user, this.pass).getBytes("UTF-8"))));
    return Collections.unmodifiableMap(map);
}

From source file:com.streamsets.lib.security.http.PlainSSOTokenGenerator.java

protected String generateData(SSOUserPrincipal principal) {
    try {//from  w  w w .j a v  a 2 s .  co  m
        String data = OBJECT_MAPPER.writeValueAsString(principal);
        return Base64.encodeBase64String(data.getBytes());
    } catch (IOException ex) {
        throw new RuntimeException(Utils.format("Should never happen: {}", ex.toString(), ex));
    }
}

From source file:ch.bfh.evoting.verifier.entities.XMLElement.java

public XMLElement(ch.bfh.unicrypt.math.algebra.general.interfaces.Element element) {
    this.value = Base64.encodeBase64String(element.getByteTree().getByteArray().getAll());
}

From source file:net.seleucus.wsp.crypto.FwknopSymmetricCrypto.java

public static String sign(byte[] auth_key, String message, byte hmac_type)
        throws NoSuchAlgorithmException, InvalidKeyException {
    // Check if hmac_type is valid
    if (hmac_type > 4 || hmac_type < 0)
        throw new IllegalArgumentException("Invalid digest type was specified");

    // Create Mac instance 
    Mac hmac;/*from www  .  j av  a2  s.co  m*/
    hmac = Mac.getInstance(HMAC_ALGORITHMS[hmac_type]);

    // Create key
    SecretKeySpec hmac_key = new SecretKeySpec(auth_key, HMAC_ALGORITHMS[hmac_type]);

    // Init hmac object
    hmac.init(hmac_key);

    // Prepare enc_part to calculate HMAC
    byte[] msg_to_hmac = FWKNOP_ENCRYPTION_HEADER.concat(message).getBytes();

    // Calculate HMAC and return
    return message.concat(Base64.encodeBase64String(hmac.doFinal(msg_to_hmac)).replace("=", ""));
}

From source file:com.fruit.core.util.IWebUtils.java

public static void setCurrentLoginSysUser(HttpServletResponse response, HttpSession httpSession,
        SysUser sysUser, Integer autoLogin) {
    setCurrentLoginSysUserToSession(httpSession, sysUser);
    if (autoLogin.equals(1)) {
        //?7//from   ww w.  ja  v  a  2  s.c  o m
        long expireTime = DateUtils.addDay(new Date(), 7).getTime();
        //????MD5???cookie
        String userInfo = MD5Utils
                .GetMD5Code(sysUser.getName() + sysUser.getPwd() + expireTime + PropKit.get("app_key"));
        String userBase64 = Base64.encodeBase64String(
                new String(sysUser.getName() + ":" + expireTime + ":" + userInfo).getBytes());
        CookieUtils.addCookie(response, "token", userBase64, 60 * 60 * 24 * 7);
    }
}

From source file:db.dao.Dao.java

public HttpResponse add(String url, Object entity) {
    url = checkIfLocal(url);/*ww w.  ja v  a2 s .  c  o  m*/

    String usernamepassword = "Pepijn:Mores";
    String encoded = Base64.encodeBase64String(usernamepassword.getBytes());

    HttpClient client = HttpClientBuilder.create().build();
    HttpPost postRequest = new HttpPost(url);
    postRequest.setHeader("content-type", "application/json");
    postRequest.setHeader("Authorization", encoded);

    String entityToJson = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        entityToJson = mapper.writeValueAsString(entity);
    } catch (JsonProcessingException ex) {
        Logger.getLogger(ArticleDao.class.getName()).log(Level.SEVERE, null, ex);
    }
    StringEntity jsonString = null;
    try {
        jsonString = new StringEntity(entityToJson);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
    }

    postRequest.setEntity(jsonString);
    HttpResponse response = null;
    try {
        response = client.execute(postRequest);
    } catch (IOException ex) {
        Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
    }
    return response;
}

From source file:com.streamsets.lib.security.http.SignedSSOTokenGenerator.java

@Override
public String getVerificationData() {
    generateKeysIfNecessary();
    return Base64.encodeBase64String(signingKeys.getPublic().getEncoded());
}

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

public String sha384Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha384(Base64.decodeBase64(dataB64)));
}

From source file:io.kahu.hawaii.util.encryption.CryptoUtil.java

public static String encrypt(String unencrypted, String key, String initVector) throws ServerException {
    try {// ww  w  .  j  a v a2s .c  o  m
        Cipher cipher = initCipher(Cipher.ENCRYPT_MODE, key, initVector);

        byte[] encrypted = cipher.doFinal(unencrypted.getBytes());
        return Base64.encodeBase64String(encrypted);
    } catch (GeneralSecurityException e) {
        throw new ServerException(ServerError.ENCRYPTION, e);
    }
}