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.coroptis.coidi.core.services.impl.ConvertorServiceImpl.java

@Override
public String convertToString(byte[] b) {
    return new String(Base64.encodeBase64(b));
}

From source file:com.enviosya.client.tool.Tool.java

public String Encriptar(String texto) {

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

    try {// w  w  w  .  j  av a  2s  .c  om

        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 e) {
        //Ac tengo que agregar el retorno de la exception
    }
    return base64EncryptedString;
}

From source file:com.google.nigori.common.TypeAdapterByteString.java

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

From source file:com.greenpepper.server.license.LicenceGenerator.java

private static void buildAcademic() throws Exception {
    File file = File.createTempFile("academic", ".lic");
    License license = License.academic("My School", _2006, _2006);
    LicenseManager lm = new LicenseManager(getLicenseParam());
    lm.store(license, file);//from   w  w w  . j a  va2  s . co  m
    if (deleteFiles)
        file.deleteOnExit();
    System.out.println("# Academic");
    System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file))));
    System.out.println("");
}

From source file:com.pureinfo.srm.reports.table.MyTabeleDataHelperTest.java

public void testGetRowMapClassArrayStringArrayStringbooleanSQLConditionStringStringArray()
        throws PureException {

    System.out.println(new String(Base64.encodeBase64(new byte[] { 1, 9, 8, 3, 6, 8 })));
}

From source file:elaborate.util.PasswordUtilTest.java

@Ignore
@Test//  w ww  .  j  av  a2s . c om
public void testPassword() throws UnsupportedEncodingException {
    final String password = "aap-noot-mies";
    final byte[] passwordDigest2 = PasswordUtil.encode(password);
    String encodedPassword = new String(Base64.encodeBase64(passwordDigest2), Charsets.UTF_8);
    assertThat(PasswordUtil.matches(password, encodedPassword)).isTrue();
    assertThat(PasswordUtil.matches("somethingelse", encodedPassword)).isFalse();
}

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

@Override
protected List<LocationDto> 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<LocationDto[]> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/location/", HttpMethod.GET, request, LocationDto[].class);
    LocationDto[] locationDtoArray = responseEntity.getBody();
    List<LocationDto> locationDtoList = new ArrayList<>();
    locationDtoList.addAll(Arrays.asList(locationDtoArray));
    return locationDtoList;
}

From source file:com.amalto.core.util.SecurityEntityResolver.java

public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    if (systemId != null) {
        Pattern httpUrl = Pattern.compile("(http|https|ftp):(\\//|\\\\)(.*):(.*)");
        Matcher match = httpUrl.matcher(systemId);
        if (match.matches()) {
            StringBuilder buffer = new StringBuilder();
            String credentials = new String(Base64.encodeBase64("admin:talend".getBytes()));
            URL url = new URL(systemId);
            URLConnection conn = url.openConnection();
            conn.setAllowUserInteraction(true);
            conn.setDoOutput(true);/*from   w  ww .j a va  2s.  co m*/
            conn.setDoInput(true);
            conn.setRequestProperty("Authorization", "Basic " + credentials);
            conn.setRequestProperty("Expect", "100-continue");
            InputStreamReader doc = new InputStreamReader(conn.getInputStream());
            BufferedReader reader = new BufferedReader(doc);
            String line = reader.readLine();
            while (line != null) {
                buffer.append(line);
                line = reader.readLine();
            }
            return new InputSource(new StringReader(buffer.toString()));
        } else {
            int mark = systemId.indexOf("file:///");
            String path = systemId.substring((mark != -1 ? mark + "file:///".length() : 0));
            File file = new File(path);
            return new InputSource(file.toURL().openStream());
        }

    }
    return null;
}

From source file:common.Util.java

public static byte[] readFile64(File file) {
    return Base64.encodeBase64(readFile(file));
}

From source file:com.example.aliyundemo.ocr.util.SignUtil.java

/**
 * ??//from  www  .j av a  2s  . co  m
 *
 * @param method               HttpMethod
 * @param url                  Path+Query
 * @param headers              Http
 * @param formParamMap         POST??
 * @param secret               APP
 * @param signHeaderPrefixList ???Header?
 * @return ???
 */
public static String sign(String method, String url, Map<String, String> headers, Map formParamMap,
        String secret, 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));

        return new String(Base64.encodeBase64(
                hmacSha256.doFinal(buildStringToSign(headers, url, formParamMap, method, signHeaderPrefixList)
                        .getBytes(Constants.ENCODING))),
                Constants.ENCODING);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}