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.vss.ogc.types.WktGzSerializer.java

@Override
public String toLiteral(Geometry geometry) {
    return new String(Base64.encodeBase64(AbstractGeo.gzip(new WKTWriter().write(geometry).getBytes())));
}

From source file:com.domainapi.util.Authenticator.java

/**
 * Generate basic authorization string for HTTP authentification.
 * //  w  w  w .  ja  v a 2  s.  c o m
 * @return basic authorization in base64.
 */
public String generateBasicAuthorization() {
    byte[] encodedPassword = (login + ":" + password).getBytes();
    return "Basic " + new String(Base64.encodeBase64(encodedPassword));
}

From source file:datafu.pig.hash.MD5Base64.java

public String call(String val) {
    return new String(Base64.encodeBase64(md5er.digest(val.getBytes())));
}

From source file:com.ec2box.manage.util.EncryptionUtil.java

/**
 * return hash value of string/*from   w  w  w .  ja  v a2  s  . c  o  m*/
 *
 * @param str  unhashed string
 * @param salt salt for hash
 * @return hash value of string
 */
public static String hash(String str, String salt) {
    String hash = null;
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        if (StringUtils.isNotEmpty(salt)) {
            md.update(Base64.decodeBase64(salt.getBytes()));
        }
        md.update(str.getBytes("UTF-8"));
        hash = new String(Base64.encodeBase64(md.digest()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hash;
}

From source file:com.keybox.manage.util.EncryptionUtil.java

/**
 * return hash value of string/*  w ww .jav  a2 s . co m*/
 *
 * @param str  unhashed string
 * @param salt salt for hash
 * @return hash value of string
 */
public static String hash(String str, String salt) {
    String hash = null;
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        if (StringUtils.isNotEmpty(salt)) {
            md.update(Base64.decodeBase64(salt.getBytes()));
        }
        md.update(str.getBytes("UTF-8"));
        hash = new String(Base64.encodeBase64(md.digest()));
    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    return hash;
}

From source file:com.orange.mmp.crypto.CipherBase64Impl.java

public byte[] encode() throws CipheringException {
    return Base64.encodeBase64(this.content);
}

From source file:com.intuit.wasabi.tests.library.ServiceGenerator.java

public static String createBasicAuthorization(String Realm, String username, String password) {
    String credentials = username + ":" + password;
    // create Base64 encoded string
    final String basic = Realm + " " + Base64.encodeBase64(credentials.getBytes());
    return basic;
}

From source file:cn.crawin.msg.gateway.http.SignUtil.java

/**
 * ??//from  w ww. j a  va2 s .c om
 *
 * @param secret APP
 * @param method HttpMethod
 * @param path
 * @param headers
 * @param querys
 * @param bodys
 * @param signHeaderPrefixList ???Header?
 * @return ???
 */
public static String sign(String secret, String method, String path, Map<String, String> headers,
        Map<String, String> querys, Map<String, String> bodys, List<String> signHeaderPrefixList) {
    try {
        Mac hmacSha256 = Mac.getInstance(Constants.HMAC_SHA256);
        byte[] keyBytes = secret.getBytes(Constants.ENCODING);
        hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, Constants.HMAC_SHA256));

        return new String(Base64.encodeBase64(
                hmacSha256.doFinal(buildStringToSign(method, path, headers, querys, bodys, signHeaderPrefixList)
                        .getBytes(Constants.ENCODING))),
                Constants.ENCODING);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:it.geosolutions.figis.persistence.dao.util.PwEncoder.java

/**
 * Encoding the password on base64//from   www  . java2s. co  m
 * @param msg
 * @return
 */
public static String encode(String msg) {
    try {
        SecretKeySpec keySpec = new SecretKeySpec(KEY, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, keySpec);

        byte[] input = msg.getBytes();
        byte[] encrypted = cipher.doFinal(input);
        byte[] output = Base64.encodeBase64(encrypted);

        return new String(output);
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (NoSuchPaddingException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (IllegalBlockSizeException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (BadPaddingException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (InvalidKeyException ex) {
        throw new RuntimeException("Error while encoding", ex);
    }
}

From source file:Conexion.newClass.java

public String encode(String texto) throws EncoderException {
    String secretKey = "mailEncrypted"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {/*from www . j a va 2 s .c  o m*/

        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;
}