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, final boolean isChunked, final boolean urlSafe,
        final int maxResultSize) 

Source Link

Document

Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.

Usage

From source file:com.revolucion.secretwit.stego.URLSteganography.java

public static String encode(String text) {
    try {/*from  w  w  w.  j  a  v a2s .  com*/
        return new String(Base64.encodeBase64(text.getBytes(DEFAULT_CHARSET), false, true, 10));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:core.SHA256Hash.java

public static String CalculateCheckSumBase64(String FileName, String url) throws Exception {
    MessageDigest md = MessageDigest.getInstance(SHA256);
    FileInputStream fileHandle = new FileInputStream(FileName);

    byte[] dataBytes = new byte[1024];

    int nread = 0;
    while ((nread = fileHandle.read(dataBytes)) != -1) {
        md.update(dataBytes, 0, nread);/* www.j a v  a2  s  .c  om*/
    }
    ;
    byte[] mdbytes = md.digest();

    byte[] bytes = null;
    if (SHA256 == getHashAlgType(url)) {
        // Do base64 encoding
        bytes = Base64.encodeBase64URLSafe(mdbytes);
    } else {
        if (SHA256_16 == getHashAlgType(url))
            bytes = Base64.encodeBase64(new byte[] { mdbytes[0], mdbytes[1] }, false, true, 4);
    }

    // Store byte array as string and return it
    String value = new String(bytes);
    System.out.println("Base64 encoded " + getHashAlgType(url) + " hash: " + value);

    return value;
}