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:Main.java

public static String toBase64String(byte[] binaryData) {
    return new String(Base64.encodeBase64(binaryData));
}

From source file:de.kaojo.security.util.SecureHashingAlgorithmHelper.java

public static String hashSHA256(String input) throws NoSuchAlgorithmException {

    MessageDigest md = MessageDigest.getInstance(ALGORITHM);

    md.update(input.getBytes());/*www . j  a  v  a  2s .c o  m*/
    byte[] digest = md.digest();

    byte[] encode = Base64.encodeBase64(digest);
    return new String(encode);
}

From source file:com.taobao.ad.easyschedule.exsession.request.session.SessionEncode.java

public static String encode(String aStr) {
    String result = null;//from   w ww .  j  a va  2s.  c  om

    try {
        if (StringUtils.isNotBlank(aStr)) {
            result = new String(Base64.encodeBase64(aStr.getBytes()));
        }
    } catch (Exception ex) {
        fLog.info(ex.getMessage());
    }

    return result;
}

From source file:encryptdecrypt.util.Security.java

public static String encrypt(String strToEncrypt) {
    try {/*from w  w  w. j  ava  2  s .  co m*/
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        return new String(Base64.encodeBase64(cipher.doFinal(strToEncrypt.getBytes())));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.hangum.tadpole.commons.libs.core.utils.Base64Utils.java

/**
 * encode base64 util/*from w  w w .j av a  2 s.  c  om*/
 * 
 * @param str
 * @return
 */
public static String base64Encode(String str) {
    byte[] encodedBytes = Base64.encodeBase64(str.getBytes());

    return new String(encodedBytes);
}

From source file:Main.java

/**
 * Comprime uma string utilizando o GZIP
 * //from w  w w.  j a v a 2 s  .  c o  m
 * @param str
 * @param encoding
 * @return
 */
public static String gzipCompressString(String str, String encoding) {
    try {
        if (str == null || str.length() == 0) {
            return null;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        Writer writer = new OutputStreamWriter(gzip, encoding);
        writer.write(str);
        writer.close();
        byte[] compressedBytes = out.toByteArray();
        return new String(Base64.encodeBase64(compressedBytes), encoding);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.duy.pascal.ui.purchase.StringXor.java

@NonNull
public static String encode(String s, String key) {
    return new String(Base64.encodeBase64(xor(s.getBytes(), key.getBytes())));
}

From source file:com.archivas.clienttools.arcutils.utils.Base64Utils.java

public static String encode(byte[] data) {
    String result = null;/* w  w w. j  a  va  2 s  .co m*/

    if (data != null) {
        // Remove trailing newline
        result = new String(Base64.encodeBase64(data)).trim();
    }

    return result;
}

From source file:com.hurence.logisland.util.string.BinaryEncodingUtils.java

public static String encode(byte[] content) throws UnsupportedEncodingException {
    return new String(Base64.encodeBase64(content), "UTF-8");
}

From source file:Main.java

static char[] encodePassword(byte[] password) {
    return new String(Base64.encodeBase64(password)).toCharArray();
}