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

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

Introduction

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

Prototype

public static byte[] encodeBase64(final byte[] binaryData) 

Source Link

Document

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

Usage

From source file:com.lankr.tv_cloud.support.qcloud.image.PicProcessSign.java

public static String sign(int appId, String secret_id, String secret_key, String bucket, long expired,
        String url) {//from   ww w. ja v  a  2  s  . c  o m
    //a=[appid]&b=[bucket]&k=[SecretID]&t=[currenTime]&e=[expiredTime]&l=[url link]
    if (empty(secret_id) || empty(secret_key)) {
        return null;
    }

    long now = System.currentTimeMillis() / 1000;
    String plain_text = String.format("a=%d&b=%s&k=%s&t=%d&e=%d&l=%s", appId, bucket, secret_id, now, expired,
            url);

    byte[] bin = HmacUtils.hmacSha1(secret_key, plain_text);

    byte[] all = new byte[bin.length + plain_text.getBytes().length];
    System.arraycopy(bin, 0, all, 0, bin.length);
    System.arraycopy(plain_text.getBytes(), 0, all, bin.length, plain_text.getBytes().length);

    all = Base64.encodeBase64(all);
    return new String(all);
}

From source file:BD.Encriptador.java

public static String Encriptar(String texto) {

    String secretKey = "qualityinfosolutions"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {//from  w  w w  .  ja v  a2s.c  om

        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);

        SecretKey key = new SecretKeySpec(keyBytes, "DESede");
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.ENCRYPT_MODE, key);

        byte[] plainTextBytes = texto.getBytes("utf-8");
        byte[] buf = cipher.doFinal(plainTextBytes);
        byte[] base64Bytes = Base64.encodeBase64(buf);
        base64EncryptedString = new String(base64Bytes);

    } catch (Exception ex) {
    }
    return base64EncryptedString;
}

From source file:com.javafxpert.wikibrowser.util.WikiBrowserUtils.java

/**
 * TODO: Move this to a util class//from  w w w .java2 s  . c o  m
 * @param username
 * @param password
 * @return
 */
public static HttpHeaders createHeaders(final String username, final String password) {
    HttpHeaders headers = new HttpHeaders() {
        {
            String auth = username + ":" + password;
            byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
            String authHeader = "Basic " + new String(encodedAuth);
            set("Authorization", authHeader);
        }
    };
    headers.add("Content-Type", "application/xml");
    headers.add("Accept", "application/xml");

    return headers;
}

From source file:com.intuit.tank.vm.common.PasswordEncoder.java

/**
 * Encodes the password using SHA-1 algorithm.
 * /*from  w w w. j  a  v  a  2  s .  c o m*/
 * @param password
 *            the password to encode
 * @return a base64 encoded has of the password.
 */
public static final String encodePassword(String password) {
    try {
        byte[] digest = MessageDigest.getInstance(DEFAULT_ALGORITHM).digest(password.getBytes());
        return new String(Base64.encodeBase64(digest));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

From source file:controlpac.EncryptHelper.java

public static String Encriptar(String texto) {
    String base64EncryptedString = "";
    try {// www.  jav  a2  s. co  m
        MessageDigest md = MessageDigest.getInstance("MD5"); //Crea un hash con la clave elegida
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede"); //Crea la clave
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.ENCRYPT_MODE, key);//Inicializa el cifrado con la clave
        byte[] plainTextBytes = texto.getBytes("utf-8");
        byte[] buf = cipher.doFinal(plainTextBytes);//Cifra el texto
        byte[] base64Bytes = Base64.encodeBase64(buf);//Encodea el texto en base64
        base64EncryptedString = new String(base64Bytes);
    } catch (Exception ex) {
    }
    return base64EncryptedString;
}

From source file:io.sidecar.security.SecurityUtils.java

/**
 * Performs base64-encoding of input bytes.
 *
 * @param rawData * Array of bytes to be encoded.
 * @return * The base64 encoded string representation of rawData.
 *///  w  ww.j  a v  a 2  s . c om
public static String encodeBase64(byte[] rawData) {
    try {
        return new String(Base64.encodeBase64(rawData), "UTF-8");
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:lib.clases_cripto.java

public static String Encriptar(String texto) {

    String secretKey = "qualityinfosolutions"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {/*  w  ww.j  a v  a2  s. co  m*/

        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(texto.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        Md5Crypt.md5Crypt(keyBytes);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] plainTextBytes = texto.getBytes("utf-8");
        byte[] buf = cipher.doFinal(plainTextBytes);
        byte[] base64Bytes = Base64.encodeBase64(buf);

        base64EncryptedString = new String(base64Bytes);

    } catch (Exception ex) {
    }
    return base64EncryptedString;
}

From source file:com.credomatic.gprod.db2query2csv.Security.java

/**
 * Codifica a base 64 una cadena de caracteres.
 * @param value Cadena de caracteres que debe ser codificada en base 64
 * @return la cadena codificada como un areglo de bytes.
 *///from  ww  w.j a  va  2 s.co m
public static byte[] encodeToBase64(final String value) {
    try {
        return Base64.encodeBase64(value.getBytes("ISO-8859-1"));
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(Security.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessSecurity.java

/**
 * Se encarga de encriptar la contrasea ingresada por el usuario *
 *//*from ww w . j a  v  a  2s. co  m*/
public static String encrypt(String value) throws BusinessException {
    String secretKey = "e-business";
    String base64EncryptedString = "";
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] plainTextBytes = value.getBytes("utf-8");
        byte[] buf = cipher.doFinal(plainTextBytes);
        byte[] base64Bytes = Base64.encodeBase64(buf);
        base64EncryptedString = new String(base64Bytes);
    } catch (Exception ex) {
        throw new BusinessException(ex);
    }
    return base64EncryptedString;
}

From source file:com.constellio.app.modules.es.connectors.http.utils.DigestUtil.java

public static String digest(final byte[] content) throws NoSuchAlgorithmException {
    MessageDigest shaDigester = MessageDigest.getInstance("SHA");
    shaDigester.update(content);//from  w  w  w  .  j  a va2s .co m
    byte[] shaDigest = shaDigester.digest();
    String digestString = new String(Base64.encodeBase64(shaDigest));

    return digestString;
}