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:cl.niclabs.tscrypto.common.datatypes.BigIntegerBase64TypeAdapter.java

@Override
public JsonElement serialize(BigInteger src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(new String(Base64.encodeBase64(src.toByteArray())));
}

From source file:com.github.imgur.api.upload.UploadRequest.java

public Map<String, Object> buildParameters() {
    final Map<String, Object> result = new HashMap<String, Object>();
    if (imageUrl != null) {
        result.put("image", imageUrl);
    } else if (imageData != null) {
        result.put("image", new String(Base64.encodeBase64(imageData)));
    }//from   w  ww . j  av  a2 s .c o  m
    if (title != null) {
        result.put("title", title);
    }

    return result;
}

From source file:it.unipmn.di.dcs.common.conversion.Convert.java

/**
 * Converts a byte array to a Base64 byte array.
 *//*  w  w w  . j  av a  2 s  .  c om*/
public static byte[] BytesToBase64Bytes(byte[] bytes) {
    if (bytes == null) {
        return null;
    }

    return Base64.encodeBase64(bytes);
}

From source file:ar.gob.ambiente.servicios.gestionpersonas.entidades.util.CriptPass.java

/**
 * Mtodo para encriptar las contraseas/*from  w w  w .  j a v  a 2  s .com*/
 * @param texto
 * @return 
 */
public static String encriptar(String texto) {

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

    try {

        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 (NoSuchAlgorithmException | UnsupportedEncodingException | NoSuchPaddingException
            | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) {
        System.out.println(ex.getMessage());
    }
    return base64EncryptedString;
}

From source file:de.mpg.escidoc.services.aa.TanStore.java

/**
 * Generate a random transaction number.
 * //  ww  w  .  j  a v a2s  . com
 * @param id The session id.
 * @return a random transaction number
 */
public static String createTan(String id) {
    Random random = new Random(new Date().getTime());

    byte[] tanBytes = new byte[16];

    random.nextBytes(tanBytes);

    return new String(Base64.encodeBase64(tanBytes));
}

From source file:at.struct.wasbugs.wasbug17.TestServlet.java

@Override
public void init() throws ServletException {
    // just to trigger an 'old' method which is around since commons-codec-1.0
    Base64.encodeBase64("hallo".getBytes());
}

From source file:com.sonatype.maven.shell.nexus.internal.wink.BasicAuthSecurityHandler.java

public BasicAuthSecurityHandler(final String username, final String password) {
    if (username != null && password != null) {
        auth = "Basic " + new String(Base64.encodeBase64((username + ":" + password).getBytes()));
    } else {/*from   w  ww  . ja va  2s.  c  o m*/
        auth = null;
    }
}

From source file:com.amazonaws.eclipse.core.ui.preferences.ObfuscatingStringFieldEditor.java

public static String encodeString(String s) {
    return new String(Base64.encodeBase64(s.getBytes()));
}

From source file:com.ljt.openapi.demo.util.SignUtil.java

/**
 * ??/*from  w w w  .ja v a2 s.  c o m*/
 * @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));

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

From source file:it.geosolutions.geofence.core.model.Base64EncodersTest.java

@Test
public void testEq() {

    String msg1 = "this is the message to encode";

    String output_codec = new String(Base64.encodeBase64(msg1.getBytes()));
    String output_dconv = DatatypeConverter.printBase64Binary(msg1.getBytes());

    System.out.println("apache commons:    " + output_codec);
    System.out.println("DatatypeConverter: " + output_dconv);
    assertEquals(output_codec, output_dconv);

    byte[] back_codec = Base64.decodeBase64(output_dconv);
    byte[] back_dconv = DatatypeConverter.parseBase64Binary(output_dconv);

    Assert.assertTrue(Arrays.equals(msg1.getBytes(), back_codec));
    Assert.assertTrue(Arrays.equals(msg1.getBytes(), back_dconv));

}