Example usage for org.apache.commons.codec.binary Base64 encodeBase64String

List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 encodeBase64String.

Prototype

public static String encodeBase64String(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm but does not chunk the output.

Usage

From source file:com.imagesleuth.imagesleuthclient2.Poster.java

public Poster(String url, String user, String password) {
    Test.testNull(url);/*  w  w  w . j a  v  a 2  s  .  c  om*/
    Test.testNull(user);
    Test.testNull(password);

    //System.out.println("user: " + user + " password: " + password);

    harray.add(new BasicHeader("Authorization",
            "Basic " + Base64.encodeBase64String((user + ":" + password).getBytes())));

    urlval = (!url.startsWith("http")) ? "http://" + url + "/api/v1/job" : url + "/api/v1/job";
    System.out.println("Poster: post url " + urlval);

    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password);
    credsProvider.setCredentials(AuthScope.ANY, credentials);
    requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(30000).build();
}

From source file:com.alliander.osgp.adapter.protocol.oslp.application.services.DeviceRegistrationService.java

public OslpDevice findDevice(final byte[] deviceId) throws ProtocolAdapterException {

    // Convert byte array to String.
    final String deviceUid = Base64.encodeBase64String(deviceId);

    final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByUid(deviceUid);
    if (oslpDevice == null) {
        throw new ProtocolAdapterException("Unable to find device using deviceUid: " + deviceUid);
    }//from   w ww.j a  v  a2  s .co m

    return oslpDevice;
}

From source file:io.druid.indexing.overlord.setup.StringEC2UserData.java

@Override
public String getUserDataBase64() {
    final String finalData;
    if (versionReplacementString != null && version != null) {
        finalData = data.replace(versionReplacementString, version);
    } else {//from ww  w.  jav a2 s .  c o m
        finalData = data;
    }
    return Base64.encodeBase64String(finalData.getBytes(Charsets.UTF_8));
}

From source file:dashboard.VersionCheck.java

public int importVersionCheckLog(int n, String apiuser, String apipass, String IPfile, String ERRfile,
        String versionCheckURL, String versionCheckPass, String API_KEY, String TOKEN, String startTime)
        throws Exception {
    int lines = 0;
    String ip = "";
    String registrant = "";
    Mixpanel mix = new Mixpanel();
    String build = "";
    String eventTime = "5/22/13 0:01 AM";
    int x = 0;//from   ww w  . j  av  a2s.  co m
    int mixpanelStatus = 0;
    int errors = 0;
    String prevIP = "";
    int index = 0;
    Registrant r;
    ArrayList<Registrant> rList = new ArrayList<Registrant>();
    ArrayList<Registrant> eList = new ArrayList<Registrant>();
    IPList ipl = new IPList();
    IPList errl = new IPList();
    Whois w = new Whois(apiuser, apipass);
    SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yy h:mm a");

    long event = 0;
    long from = sdf.parse(startTime).getTime();
    int nn = 1;

    System.out.println(">>>  Version Check log - " + versionCheckURL);
    URL logURL = new URL(versionCheckURL);
    String base64EncodedString = Base64.encodeBase64String(StringUtils.getBytesUtf8(versionCheckPass));

    URLConnection conn = logURL.openConnection();
    conn.setRequestProperty("Authorization", "Basic " + base64EncodedString);

    InputStream in = conn.getInputStream();
    BufferedReader br = null;

    try {
        br = new BufferedReader(new InputStreamReader(in));
        String inputLine = br.readLine();

        // Skip first line (headers)
        if (inputLine != null)
            inputLine = br.readLine();

        // Load list of IP - REGISTRANT               
        ipl.loadList(rList, IPfile);
        ipl.printList(rList, 5);

        // Loop - limited to n cycles (parameter defined by user)
        while (inputLine != null & lines < n) {
            String[] dataArray = inputLine.split(",");
            x = 0;
            for (String ttt : dataArray)
                x++;
            if (x == 3) {
                ip = dataArray[0];
                build = dataArray[1];
                eventTime = dataArray[2];
            } else if (x == 4) {
                // Line format is corrupted (2 ip's)
                errors++;
                ip = dataArray[1];
                build = dataArray[2];
                eventTime = dataArray[3];
            }

            event = sdf.parse(eventTime).getTime();
            if (event < from) {
                nn++;
                //System.out.print(nn + ", ");   
                inputLine = br.readLine(); // Read next line of data.
                continue;
            }

            if (lines == 0) {
                System.out.println("------  Skipped " + nn + " events --------");
                System.out.println();
            }

            if (ip != prevIP) {
                prevIP = ip;

                index = ipl.ipInList(ip, rList);
                if (index >= 0) {
                    r = rList.get(index);
                    registrant = r.name;
                    // Update counter for this IP
                    r.counter = r.counter + 1;
                    rList.set(index, r);
                } else {
                    // WHOIS - Check registrant of this IP address
                    registrant = w.whoisIP(ip);

                    // if there was an error, try again
                    if (registrant.equals("ERROR"))
                        registrant = w.whoisIP(ip);

                    // if there was a second error, add it to errors list
                    if (registrant.equals("ERROR")) {
                        eList.add(new Registrant(ip, registrant, 1));
                    } else {
                        // If name includes a comma, exclude the comma
                        registrant = registrant.replace(",", "");
                        rList.add(new Registrant(ip, registrant, 1));
                    }
                }
            }

            inputLine = br.readLine(); // Read next line of data.
            lines++;

            System.out.println(">> " + lines + " - " + eventTime + "  " + ip + " - " + registrant);

            // Track the event in Mixpanel (using the POST import) - event time is in the PAST
            mix.postVersionCheckToMixpanel(API_KEY, TOKEN, ip, registrant, "Version Check", eventTime, build);

        } // while
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        // Close the file once all data has been read.
        if (br != null)
            br.close();

        ipl.printList(rList, 5);
        ipl.saveList(rList, IPfile);

        if (!eList.isEmpty()) {
            sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
            String fName = ERRfile + sdf.format(new Date()) + ".txt";

            System.out.println("\n>>> " + eList.size() + " DomainTools errors:");
            errl.saveList(eList, fName);
        } else
            System.out.println("\n>>> No DomainTools errors");

        return lines;
    }
}

From source file:edu.tamu.tcat.crypto.spongycastle.PBKDF2Impl.java

@Override
protected String deriveHash(byte[] password, int rounds, byte[] salt) {
    int outputSize = bouncyDigest.getDigestSize();

    String hashType;//from   ww  w.ja  v a 2 s  .  c  o m
    if (digest == DigestType.SHA1)
        hashType = "pbkdf2";
    else
        hashType = "pbkdf2-" + digest.name().toLowerCase();
    byte[] output = deriveKey(password, salt, rounds, outputSize);
    return "$" + hashType + "$" + rounds + "$" + Base64.encodeBase64String(salt).replace('+', '.') + "$"
            + Base64.encodeBase64String(output).replace('+', '.');
}

From source file:br.eti.fernandoribeiro.rhq.cloudserverpro.SignatureClientFilter.java

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;//w w w  .  jav  a  2s. com

    try {
        final Map<String, List<Object>> headers = request.getHeaders();

        final List<Object> value = new ArrayList<Object>();

        final DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");

        final String timestamp = formatter.format(date);

        final Hex encoder = new Hex();

        final MessageDigest digester = MessageDigest.getInstance("SHA1");

        value.add(login + ":" + timestamp + ":" + Base64.encodeBase64String(
                encoder.encode(digester.digest((login + contentLength + timestamp + secretKey).getBytes()))));

        headers.put(HeaderNames.API_SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
    }

    return result;
}

From source file:com.splicemachine.olap.DistributedCompaction.java

public String base64EncodedFileList() {
    assert files instanceof Serializable : "Non-serializable list specified!";
    return Base64.encodeBase64String(SerializationUtils.serialize((Serializable) files));
}

From source file:info.fcrp.keepitsafe.bean.UserBeanTest.java

private String generatePublicKey() throws NoSuchAlgorithmException {
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(1024, new SecureRandom());
    KeyPair kp = kpg.generateKeyPair();
    PublicKey pubKey = kp.getPublic();

    return Base64.encodeBase64String(pubKey.getEncoded());
}

From source file:com.cloud.consoleproxy.ConsoleProxy.java

private static String genDefaultEncryptorPassword() {
    try {//from   w  w  w  .  j  a v  a2  s  .com
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");

        byte[] randomBytes = new byte[16];
        random.nextBytes(randomBytes);
        return Base64.encodeBase64String(randomBytes);
    } catch (NoSuchAlgorithmException e) {
        s_logger.error("Unexpected exception ", e);
        assert (false);
    }

    return "Dummy";
}

From source file:com.consol.citrus.validation.text.BinaryBase64MessageValidatorTest.java

@Test
public void testBinaryBase64ValidationError() {
    Message receivedMessage = new DefaultMessage("Hello World!".getBytes());
    Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello Citrus!".getBytes()));

    ValidationContext validationContext = new DefaultValidationContext();
    try {/*from w ww.  jav  a2  s . c  om*/
        validator.validateMessagePayload(receivedMessage, controlMessage, validationContext, context);
    } catch (ValidationException e) {
        Assert.assertTrue(e.getMessage().contains("expected 'SGVsbG8gQ2l0cnVzIQ=='"));
        Assert.assertTrue(e.getMessage().contains("but was 'SGVsbG8gV29ybGQh'"));

        return;
    }

    Assert.fail("Missing validation exception due to wrong number of JSON entries");
}