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:microsoft.exchange.webservices.data.property.definition.ByteArrayPropertyDefinition.java

/**
 * Converts byte array property to a string.
 *
 * @param value accepts Object/*from w  w  w .java  2  s .c om*/
 * @return value
 */
@Override
protected String toString(byte[] value) {
    return Base64.encodeBase64String(value);
}

From source file:com.continusec.client.MapTreeHead.java

/**
 * Implementation of getLeafHash() so that MapTreeHead can be used easily with
 * {@link VerifiableLog#verifyInclusion(LogTreeHead, MerkleTreeLeaf)}.
 * @return leaf hash base on the Object Hash for this map root hash with corresponding mutation log.
 * @throws ContinusecException upon error
 *///from  w  ww. j  ava 2s  .  c o  m
public byte[] getLeafHash() throws ContinusecException {
    if (this.oh == null) {
        JsonObject ml = new JsonObject();
        ml.addProperty("tree_size", this.getMutationLogTreeHead().getTreeSize());
        ml.addProperty("tree_hash", Base64.encodeBase64String(this.getMutationLogTreeHead().getRootHash()));

        JsonObject mapo = new JsonObject();
        mapo.addProperty("map_hash", Base64.encodeBase64String(this.getRootHash()));
        mapo.add("mutation_log", ml);

        this.oh = Util.leafMerkleTreeHash(ObjectHash.objectHash(mapo));
    }
    return this.oh;
}

From source file:de.decoit.visa.protocol.Response.java

/**
 * Construct a new Response object using the specified return code, data and
 * message. Message can be set to null if no message is required, it will
 * translated into an empty String internally.
 *
 * @param pCode Return code of this Response
 * @param pData Map containing the data included in this Response
 * @param pMsg Optional response message, can be null if not required
 *///w  ww.  j  a v  a  2  s  .  c  o  m
public Response(int pCode, Map<String, String> pData, String pMsg) {
    returnCode = pCode;

    data = new HashMap<>();

    for (Map.Entry<String, String> s : pData.entrySet()) {
        String key = Base64.encodeBase64String(s.getKey().getBytes());
        String value = Base64.encodeBase64String(s.getValue().getBytes());
        data.put(key, value);
    }

    if (pMsg != null) {
        message = Base64.encodeBase64String(pMsg.getBytes());
    } else {
        message = "";
    }
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.bitbucket.BitbucketArtifactCredentials.java

public BitbucketArtifactCredentials(BitbucketArtifactAccount account, OkHttpClient okHttpClient,
        ObjectMapper objectMapper) {//from  w  w  w. j a  v a2  s  . c om
    this.name = account.getName();
    this.okHttpClient = okHttpClient;
    this.objectMapper = objectMapper;
    Builder builder = new Request.Builder();
    boolean useLogin = !StringUtils.isEmpty(account.getUsername())
            && !StringUtils.isEmpty(account.getPassword());
    boolean useUsernamePasswordFile = !StringUtils.isEmpty(account.getUsernamePasswordFile());
    boolean useAuth = useLogin || useUsernamePasswordFile;
    if (useAuth) {
        String authHeader = "";
        if (useUsernamePasswordFile) {
            authHeader = Base64
                    .encodeBase64String((credentialsFromFile(account.getUsernamePasswordFile())).getBytes());
        } else if (useLogin) {
            authHeader = Base64
                    .encodeBase64String((account.getUsername() + ":" + account.getPassword()).getBytes());
        }
        builder.header("Authorization: Basic ", authHeader);
        log.info("Loaded credentials for Bitbucket artifact account {}", account.getName());
    } else {
        log.info("No credentials included with Bitbucket artifact account {}", account.getName());
    }
    requestBuilder = builder;
}

From source file:it.jnrpe.plugin.tomcat.TomcatDataProvider.java

public void init(String hostname, String uri, int port, String username, String password, boolean useSSL,
        int timeout) throws Exception {

    this.uri = uri;
    this.port = port;
    this.username = username;
    this.password = password;
    this.hostname = hostname;
    this.useSSL = useSSL;

    // Retrieve tomcat xml...
    String encoded = Base64.encodeBase64String((username + ":" + password).getBytes("UTF-8"));
    Properties props = new Properties();
    props.setProperty("Authorization", "Basic " + encoded);
    String response = Utils.getUrl(new URL(getUrl()), props, timeout * 1000);

    if (response == null) {
        throw new Exception("Null response received from tomcat");
    }/*from  www.  ja va2  s .  c o m*/
    tomcatXML = response;

    parseMemoryData();
    parseMemoryPools();
    parseConnectorsThreadData();
}

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

/**
 * HmacMD5/*from   w  w  w .j a  v  a2s  .  c om*/
 *
 * @param keyB64 Secret key Base64 encoded
 * @param dataB64 Data to sign Base64 encoded
 * @return HmacMd5 MAC for the given key and data Base64 encoded
 */
public String hmacMd5(String keyB64, String dataB64) {
    validateB64(keyB64);
    validateB64(dataB64);
    final byte[] key = Base64.decodeBase64(keyB64);
    final byte[] data = Base64.decodeBase64(dataB64);

    return Base64.encodeBase64String(HmacUtils.hmacMd5(key, data));
}

From source file:com.almende.util.EncryptionUtil.java

/**
 * Encrypt a string.//from  ww w  .  ja  va  2s .  c om
 * 
 * @param text
 *            the text
 * @return encryptedText
 * @throws InvalidKeyException
 *             the invalid key exception
 * @throws InvalidAlgorithmParameterException
 *             the invalid algorithm parameter exception
 * @throws NoSuchAlgorithmException
 *             the no such algorithm exception
 * @throws InvalidKeySpecException
 *             the invalid key spec exception
 * @throws NoSuchPaddingException
 *             the no such padding exception
 * @throws IllegalBlockSizeException
 *             the illegal block size exception
 * @throws BadPaddingException
 *             the bad padding exception
 * @throws UnsupportedEncodingException
 *             the unsupported encoding exception
 */
public static String encrypt(final String text) throws InvalidKeyException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException,
        BadPaddingException, UnsupportedEncodingException {
    final PBEParameterSpec pbeParamSpec = new PBEParameterSpec(S, C);
    final PBEKeySpec pbeKeySpec = new PBEKeySpec(P);
    final SecretKeyFactory keyFac = SecretKeyFactory.getInstance(ENC);
    final SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

    final Cipher pbeCipher = Cipher.getInstance(ENC);
    pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

    final byte[] encryptedText = pbeCipher.doFinal(text.getBytes("UTF-8"));
    return Base64.encodeBase64String(encryptedText);
}

From source file:com.grosscommerce.ICEcat.utilities.Downloader.java

private static HttpURLConnection prepareConnection(String urlFrom, String login, String pwd)
        throws ProtocolException, IOException, MalformedURLException {
    URL url = new URL(urlFrom);
    HttpURLConnection uc = (HttpURLConnection) url.openConnection();
    // set up url connection to get retrieve information back
    uc.setRequestMethod("GET");
    uc.setDoInput(true);/*from w w  w .  j a v a 2s  .co m*/
    String val = (new StringBuffer(login).append(":").append(pwd)).toString();
    byte[] base = val.getBytes();
    String authorizationString = "Basic " + Base64.encodeBase64String(base);
    uc.setRequestProperty("Authorization", authorizationString);
    uc.setRequestProperty("Accept-Encoding", "gzip, xml");
    return uc;
}

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

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;/*  w  w  w .  j a v  a2 s . c o  m*/

    try {
        log.info("Adding signature to request");

        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.SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
        log.error("Can't handle request", e);
    }

    return result;
}

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

@Override
public ClientResponse handle(final ClientRequest request) {
    ClientResponse result = null;//from  w  w w. j  av  a 2s  . c o m

    try {
        logger.println("Adding signature to request");

        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.SIGNATURE, value);

        result = getNext().handle(request);
    } catch (final NoSuchAlgorithmException e) {
        logger.println("Can't handle request");
    }

    return result;
}