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:Clases.cCifrado.java

public String Encriptar(String texto) {

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

    try {//from www  .j  av a 2 s .co 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 "Ha habido un problema enviando datos";
    }
    return base64EncryptedString;
}

From source file:com.wso2telco.gsma.authenticators.cryptosystem.AESencrp.java

/**
 * Encrypt./*from w w w. j  a  v  a2s  .co  m*/
 *
 * @param Data the data
 * @return the string
 * @throws Exception the exception
 */
public static String encrypt(String Data) throws Exception {
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encVal = c.doFinal(Data.getBytes());
    //String encryptedValue = new BASE64Encoder().encode(encVal);
    byte[] encryptedValue = Base64.encodeBase64(encVal);
    return new String(encryptedValue);
}

From source file:com.dv.meetmefor.ws.controller.BinaryDataContoller.java

public String download(String id) {
    Integer idInt = Integer.valueOf(id);
    BinaryData binaryData = binaryDataDao.find(idInt);
    byte[] data = Base64.encodeBase64(binaryData.getData());
    return new String(data);
}

From source file:net.firejack.aws.license.LicenseHelper.java

private static void signature(License license) throws UnsupportedEncodingException, NoSuchAlgorithmException {
    StringBuilder builder = new StringBuilder();
    builder.append(license.getExpired()).append(license.getName()).append(license.getSession());
    byte[] bytes = builder.toString().getBytes("UTF-8");

    for (int i = 0; i < bytes.length; i += 2)
        bytes[i] += i;//  w  ww  . j av a  2  s  .  c om

    MessageDigest digest = MessageDigest.getInstance("MD5");
    license.setSignature(new String(Base64.encodeBase64(digest.digest(bytes))));
}

From source file:com.vmware.o11n.plugin.crypto.service.CryptoEncodingService.java

/**
 *
 * @param data/*w w w  .  j  av  a  2s  .  c om*/
 * @return
 * @throws UnsupportedEncodingException
 */
public String base64Encode(byte[] data) throws UnsupportedEncodingException {
    String encoded = new String(Base64.encodeBase64(data));
    return encoded;
}

From source file:com.amazon.pay.impl.Util.java

/**
 * Helper method to calculate base64 encoded signature using specified secret key
 *
 *//*  ww w  . j ava 2  s .co  m*/
public static String getSignature(String stringToSign, String secretKey) throws IllegalStateException,
        InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256"));
    byte[] signature = mac.doFinal(stringToSign.getBytes("UTF-8"));
    String signatureBase64 = new String(Base64.encodeBase64(signature), "UTF-8");
    return signatureBase64;
}

From source file:com.kolich.common.util.crypt.Base64Utils.java

/**
 * Encodes binary data using the base64 algorithm but
 * does not chunk the output.//w w w .  j ava  2s .  c om
 * @param encode
 * @return
 */
public static final byte[] encodeBase64(final byte[] encode) {
    return Base64.encodeBase64(encode);
}

From source file:edu.clemson.lph.utils.Encodings.java

/**
 * Convert a String--normally XML--into Windows .Net format string (UTF-16 with Little Endian byte order)
 * encoded in base64 binary String format.  Used to populate base64Binary fields in .Net generated SOAP 
 * services.  Edit the WSDL prior to code generation to accept a string instead of a base64Binary type
 * because SOAP would generate that in UTF-8.
 * @param sXML//from w w w . j ava  2  s  . c  o  m
 * @return String in base64
 */
public static String getBase64Utf16Le(String sXML) {
    String sBase64 = null;
    byte[] bytes;
    try {
        bytes = sXML.getBytes("UTF-16LE"); // Tested, specifying little endian really is essential.
        byte[] base64Bytes = Base64.encodeBase64(bytes);
        sBase64 = new String(base64Bytes);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sBase64;
}

From source file:com.eviware.soapui.impl.wsdl.support.CompressedStringSupport.java

public static void setString(CompressedStringConfig compressedStringConfig, String value) {
    synchronized (compressedStringConfig) {
        long limit = SoapUI.getSettings().getLong(WsdlSettings.COMPRESSION_LIMIT, 0);
        if (limit > 0 && value.length() >= limit) {
            try {
                ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
                GZIPOutputStream out = new GZIPOutputStream(byteOut);
                out.write(value.getBytes());
                out.finish();//from  w  w w.j av  a2 s  .  co  m
                value = new String(Base64.encodeBase64(byteOut.toByteArray()));
                compressedStringConfig.setCompression("gzip");
            } catch (IOException e) {
                SoapUI.logError(e);
                compressedStringConfig.unsetCompression();
            }
        } else if (compressedStringConfig.isSetCompression()) {
            compressedStringConfig.unsetCompression();
        }

        compressedStringConfig.setStringValue(value);
    }
}

From source file:com.google.nigori.server.JUser.java

@Override
public String getName() {
    return bytesToString(Base64.encodeBase64(getPublicKey()));
}