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) 

Source Link

Document

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

Usage

From source file:com.emc.ecs.s3.sample.ECSS3Factory.java

public static void main(String[] args) {
    try {/* w w w .  ja  v a  2s.  co m*/
        KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
        keyGenerator.initialize(1024, new SecureRandom());
        KeyPair myKeyPair = keyGenerator.generateKeyPair();

        // Serialize.
        byte[] pubKeyBytes = myKeyPair.getPublic().getEncoded();
        byte[] privKeyBytes = myKeyPair.getPrivate().getEncoded();

        String pubKeyStr = new String(Base64.encodeBase64(pubKeyBytes, false), "US-ASCII");
        String privKeyStr = new String(Base64.encodeBase64(privKeyBytes, false), "US-ASCII");

        System.out.println("Public Key: " + pubKeyStr);
        System.out.println("Private Key: " + privKeyStr);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String encodeBase64(Element elm) throws Exception {
    ByteArrayOutputStream ostream = new ByteArrayOutputStream();
    TransformerFactory transFac = TransformerFactory.newInstance();
    Transformer trans = transFac.newTransformer();
    trans.transform(new DOMSource(elm), new StreamResult(ostream));
    return (new String(Base64.encodeBase64(ostream.toByteArray(), true)));
}

From source file:com.roncoo.adminlte.util.Base64Util.java

/**
 * //from   w  w w .jav a2s. c  o m
 * 
 * @param key
 * @return
 */
public static String encrypt(String key) {
    byte[] ec = Base64.encodeBase64(key.getBytes(), true);
    String ec_result = new String(ec).replaceAll("\r|\n", "");
    return ec_result;
}

From source file:com.google.step2.util.EncodingUtil.java

public static String encodeBase64(byte[] bytes) {
    return EncodingUtil.getUtf8String(Base64.encodeBase64(bytes, false));
}

From source file:aiai.apps.gen_keys.GenerateKeys.java

public static String encodeBase64String(final byte[] binaryData) {
    return StringUtils.newStringUsAscii(Base64.encodeBase64(binaryData, true));
}

From source file:librarymanagementsystem.Base64Converter.java

/**
 * This method converts the content of a source file into Base64 encoded
 * data and saves that to a target file. If isChunked parameter is set to
 * true, there is a hard wrap of the output encoded text.
 *///from   w ww . ja  va  2  s.co  m
private static void encode(String sourceFile, String targetFile, boolean isChunked) throws Exception {

    byte[] base64EncodedData = Base64.encodeBase64(loadFileAsBytesArray(sourceFile), isChunked);

    writeByteArraysToFile(targetFile, base64EncodedData);
}

From source file:aiai.apps.commons.utils.SecUtils.java

public static String getSignature(String data, PrivateKey privateKey, boolean isChuncked)
        throws GeneralSecurityException {
    Signature signer = Signature.getInstance("SHA256withRSA");
    signer.initSign(privateKey);//from   w ww  . j  a v a2 s.co  m
    signer.update(data.getBytes(StandardCharsets.UTF_8));
    return StringUtils.newStringUsAscii(Base64.encodeBase64(signer.sign(), isChuncked));
}

From source file:com.ecama.utils.ImageEncoder.java

public List<String> encodeImage(List<Files> imageData) {
    List<String> imageList = new ArrayList<String>();
    if (!imageData.isEmpty()) {
        for (Files file : imageData) {
            StringBuilder sb = new StringBuilder();
            sb.append("data:image/jpg;base64,");
            sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(file.getFile(), false)));
            imageList.add(sb.toString());
        }/*from   www . j a v a2s  . c  om*/

    }
    return imageList;
}

From source file:jp.co.golorp.emarf.util.CryptUtil.java

/**
 * 16???AES???Base64????//from w w w  .  ja v a  2 s . c o  m
 *
 * @param string
 *            
 * @return ?
 */
public static String encrypt(final String string) {

    if (string == null) {
        return null;
    }

    byte[] input = string.getBytes();

    byte[] encryped = cipher(Cipher.ENCRYPT_MODE, input);

    byte[] encoded = Base64.encodeBase64(encryped, false);

    String ret = new String(encoded);

    LOG.debug("Encrypt [" + string + "] to [" + ret + "].");

    return ret;
}

From source file:com.comcast.cereal.convert.ByteArrayCerealizer.java

public String cerealize(byte[] object, ObjectCache objectCache) throws CerealException {
    return new String(Base64.encodeBase64(object, false));
}