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:com.aipo.aws.ses.SES.java

protected static String encodeWordJIS(String s) {
    try {//from   w  w  w .j av a  2  s.com
        return "=?ISO-2022-JP?B?" + new String(Base64.encodeBase64(s.getBytes("ISO-2022-JP"))) + "?=";
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("CANT HAPPEN");
    }
}

From source file:id.co.teleanjar.ppobws.restclient.RestClientService.java

public HttpHeaders createHeaders(final String username, final String password) {
    return new HttpHeaders() {
        {//from  w  ww  .  ja v a 2  s .c  o m
            String auth = username + ":" + password;
            byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
            String authHeader = "Basic " + new String(encodedAuth);
            set("Authorization", authHeader);
        }
    };
}

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

/**
 * Encrypt.// ww  w  .j a  va2s .c o 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);
    String encryptedValue = new String(Base64.encodeBase64(encVal));
    return encryptedValue;
}

From source file:com.navercorp.pinpoint.rpc.packet.PayloadPacket.java

public static byte[] encodeBase64(final ChannelBuffer header, final byte[] payload) {
    if (payload == null) {
        // this is also payload header
        header.writeInt(-1);/*  w  ww .  j  a va 2 s  .co m*/
        byte[] realBuf = new byte[header.writerIndex()];
        header.getBytes(0, realBuf);
        return Base64.encodeBase64(realBuf);
    } else {
        header.writeInt(payload.length);
        ChannelBuffer payloadWrap = ChannelBuffers.wrappedBuffer(payload);
        ChannelBuffer realData = ChannelBuffers.wrappedBuffer(true, header, payloadWrap);
        byte[] realBuf = new byte[realData.writerIndex()];
        realData.getBytes(0, realBuf);
        return Base64.encodeBase64(realBuf);
    }
}

From source file:cz.muni.fi.mushroomhunter.restclient.AllMushroomsSwingWorker.java

@Override
protected List<MushroomDto> doInBackground() throws Exception {
    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity<String> request = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<MushroomDto[]> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/mushroom/", HttpMethod.GET, request, MushroomDto[].class);
    MushroomDto[] mushroomDtoArray = responseEntity.getBody();
    List<MushroomDto> mushroomDtoList = new ArrayList<>();
    mushroomDtoList.addAll(Arrays.asList(mushroomDtoArray));
    return mushroomDtoList;
}

From source file:com.pieframework.runtime.utils.CertificateUtils.java

public static String encryptPassword(String rdpPassword, X509Certificate certificate) {
    Security.addProvider(new BouncyCastleProvider());
    String encryptedPassword = "";
    //get PrivateKey And certificate from pfx file
    try {/*w w  w.j ava 2s  . co m*/

        certificate.checkValidity();

        CMSEnvelopedDataGenerator envDataGen = new CMSEnvelopedDataGenerator();
        envDataGen.addKeyTransRecipient(certificate);
        CMSProcessable envData = new CMSProcessableByteArray(rdpPassword.getBytes());
        CMSEnvelopedData enveloped = envDataGen.generate(envData, CMSEnvelopedDataGenerator.DES_EDE3_CBC, "BC");
        byte[] data = enveloped.getEncoded();
        encryptedPassword = new String(Base64.encodeBase64(data));

    } catch (Exception e) {
        e.printStackTrace();
    }

    return encryptedPassword;
}

From source file:com.cloud.util.NuageVspUtil.java

public static String encodePassword(String originalPassword) {
    byte[] passwordBytes = originalPassword.getBytes(StringUtils.getPreferredCharset());
    byte[] encodedPasswordBytes = Base64.encodeBase64(passwordBytes);
    return new String(encodedPasswordBytes, StringUtils.getPreferredCharset());
}

From source file:net.enilink.komma.em.internal.ByteArrayConverter.java

@Override
public ILiteral serialize(byte[] data) {
    return lf.createLiteral(new String(Base64.encodeBase64(data)), getDatatype(), null);
}

From source file:com.lecaddyfute.utils.security.AESCrypto.java

public static String encrypt(String Data) throws Exception {
    Key key = generateKey();//from   ww w .j  a  v a 2  s  . c  o  m
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encVal = c.doFinal(Data.getBytes());
    String encryptedValue = new String(Base64.encodeBase64(encVal));
    return encryptedValue;
}

From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.CounterRollupSerializationTest.java

@Test
public void testCounterV1RoundTrip() throws IOException {
    BluefloodCounterRollup c0 = new BluefloodCounterRollup().withCount(7442245).withSampleCount(1);
    BluefloodCounterRollup c1 = new BluefloodCounterRollup().withCount(34454722343L).withSampleCount(10);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(Base64.encodeBase64(Serializers.counterRollupInstance.toByteBuffer(c0).array()));
    baos.write("\n".getBytes());
    baos.write(Base64.encodeBase64(Serializers.counterRollupInstance.toByteBuffer(c1).array()));
    baos.write("\n".getBytes());

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    BufferedReader reader = new BufferedReader(new InputStreamReader(bais));

    ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
    BluefloodCounterRollup cc0 = Serializers.serializerFor(BluefloodCounterRollup.class).fromByteBuffer(bb);
    Assert.assertEquals(c0, cc0);//from  w w w  . j a v a 2  s  .  co  m

    bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
    BluefloodCounterRollup cc1 = Serializers.serializerFor(BluefloodCounterRollup.class).fromByteBuffer(bb);

    Assert.assertEquals(c1, cc1);
    Assert.assertFalse(cc0.equals(cc1));
}