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

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

Introduction

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

Prototype

public static String encodeBase64URLSafeString(final byte[] binaryData) 

Source Link

Document

Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.

Usage

From source file:org.eclipse.che.vfs.impl.fs.LocalFileSystemTest.java

protected String pathToId(String path) {
    if ("/".equals(path)) {
        return ROOT_ID;
    }/*from w  w  w  .j ava2 s .  co  m*/
    try {
        return Base64.encodeBase64URLSafeString((MY_WORKSPACE_ID + ':' + path).getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // Should never happen.
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:org.eclipse.orion.server.servlets.XSRFPreventionFilter.java

private String generateNonce(String method, String path) {
    byte[] randomBytes = new byte[24];
    secureRandom.nextBytes(randomBytes);
    String nonce = Base64.encodeBase64URLSafeString(randomBytes);
    if (LOG.isDebugEnabled()) {
        LOG.debug(MessageFormat.format("Creating nonce  for {0} {1}: ''{2}''", method, path, nonce));
    }/*from  ww  w  .  j a  v  a 2 s .c  o  m*/
    return nonce;
}

From source file:org.excalibur.driver.google.compute.GoogleCompute.java

protected Instance createInstanceFromTemplate(InstanceTemplate template) {
    Instance instance = new Instance().setMachineType(template.getInstanceType().getName())
            .setName(template.getInstanceName()).setNetworkInterfaces(new ArrayList<NetworkInterface>());

    instance.getNetworkInterfaces()/*  w  w w .ja  v  a  2 s .c  o m*/
            .add(new NetworkInterface().setAccessConfigs(new ArrayList<AccessConfig>())
                    .setNetwork(String.format(
                            "https://www.googleapis.com/compute/v1/projects/%s/global/networks/default",
                            credentials_.getProject())));
    instance.getNetworkInterfaces().get(0).getAccessConfigs()
            .add(new AccessConfig().setName("External NAT").setType("ONE_TO_ONE_NAT"));

    instance.setZone(template.getRegion().getName());
    instance.setMachineType(
            getMachineType(instance.getZone(), template.getInstanceType().getName()).getSelfLink());

    instance.setDisks(new ArrayList<AttachedDisk>());
    instance.getDisks().add(new AttachedDisk().setType("PERSISTENT").setAutoDelete(false).setBoot(true)
            .setMode("READ_WRITE")
            .setInitializeParams(new AttachedDiskInitializeParams().setDiskName(template.getInstanceName())
                    .setDiskSizeGb(
                            SystemUtils2.getIntegerProperty("org.excalibur.default.disk.size", 10).longValue())
                    .setSourceImage(VM_IMAGES_NAME_MAPPING.get(template.getImageId()))));

    List<Items> items = new ArrayList<Metadata.Items>();

    Metadata metadata = new Metadata().setItems(items);
    instance.setMetadata(metadata);

    items.add(new Items().setKey("sshKeys")
            .setValue(String.format("%s:%s", template.getLoginCredentials().getUser(),
                    decrypt(template.getLoginCredentials().getPublicKey()).replaceAll("\n", ""))));

    items.add(new Items().setKey("image-id").setValue(template.getImageId()));
    items.add(new Items().setKey("keyname").setValue(template.getKeyName().toLowerCase()));
    items.add(new Items().setKey("zone").setValue(instance.getZone()));
    items.add(new Items().setKey("platform").setValue(Platform.LINUX.name().toLowerCase()));
    items.add(new Items().setKey("platform-username").setValue(template.getLoginCredentials().getUser()));
    items.add(new Items().setKey("owner").setValue(template.getLoginCredentials().getUser()));
    items.add(new Items().setKey("pem-key").setValue(
            Base64.encodeBase64URLSafeString(template.getLoginCredentials().getPrivateKey().getBytes())));

    for (Tag tag : template.getTags()) {
        items.add(new Items().setKey(tag.getName()).setValue(tag.getValue()));
    }

    return instance;
}

From source file:org.exoplatform.mongo.util.EncodingUtils.java

public final static String encodeBase64(String toEncode, boolean urlSafe) {
    String encoded = null;// w ww .  ja  v a 2s. c o m
    try {
        if (!StringUtils.isNullOrEmpty(toEncode)) {
            if (urlSafe) {
                encoded = Base64.encodeBase64URLSafeString(toEncode.trim().getBytes(UTF_CHARSET_ENCODING));
            } else {
                encoded = Base64.encodeBase64String(toEncode.trim().getBytes(UTF_CHARSET_ENCODING));
            }
        }
    } catch (UnsupportedEncodingException unsupportedEncodingException) {
        // Stupid exception - low likelihood of getting hit by it
        throw new RuntimeException(unsupportedEncodingException);
    }
    return encoded;
}

From source file:org.faster.util.Encrypts.java

/**
 * ?//w ww. j  a v a 2 s . co m
 *
 * @param algorithm ??
 * @param plainText 
 * @param salt ?
 * @return ?
 */
public static final String encrypt(String algorithm, String plainText, String salt) {
    MessageDigest md;
    try {
        md = MessageDigest.getInstance(algorithm);
    } catch (Exception e) {
        throw Exceptions.unchecked(e);
    }

    md.reset();
    if (salt != null) {
        md.update(salt.getBytes());
    }
    byte[] unencodedText = plainText.getBytes();
    md.update(unencodedText);

    byte[] encodedText = md.digest();
    return Base64.encodeBase64URLSafeString(encodedText);
}

From source file:org.fcrepo.oai.service.OAIProviderService.java

public static String encodeResumptionToken(String verb, String metadataPrefix, String from, String until,
        String set, int offset) throws UnsupportedEncodingException {
    if (from == null) {
        from = "";
    }/*  ww w  . ja v  a2s  .c o m*/
    if (until == null) {
        until = "";
    }
    if (set == null) {
        set = "";
    }
    String[] data = new String[] { urlEncode(verb), urlEncode(metadataPrefix), urlEncode(from),
            urlEncode(until), urlEncode(set), urlEncode(String.valueOf(offset)) };
    return Base64.encodeBase64URLSafeString(StringUtils.join(data, ':').getBytes("UTF-8"));
}

From source file:org.gravidence.gravifon.util.BasicUtils.java

/**
 * Encodes a string according to URL safe base64 rules. UTF-8 character encoding is used.
 * // w w  w  . j a  v  a  2s . c o m
 * @param input clear text string
 * @return encoded string
 */
public static String encodeToBase64(String input) {
    String result;

    if (input == null) {
        result = null;
    } else {
        try {
            result = Base64.encodeBase64URLSafeString(input.getBytes(CharEncoding.UTF_8));
        } catch (UnsupportedEncodingException ex) {
            throw new GravifonException(GravifonError.UNEXPECTED,
                    "UTF-8 encoding is not supported by underlying system.", ex);
        }
    }

    return result;
}

From source file:org.i3xx.step.clock.util.StoreUtils.java

public static String serialize(Object object) {
    try {//from w  w w.  j av a  2  s  .co m
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(object);
        return Base64.encodeBase64URLSafeString(bos.toByteArray());
    } catch (Exception e) {
        throw new RuntimeException("serialize session error", e);
    }
}

From source file:org.i3xx.step.mongo.core.util.IdGen.java

/**
 * Gets a 128 bit IdRep in an URL save representation (slow)
 * /*from w  w  w.ja  v  a2  s .  co m*/
 * @return The IdRep object
 */
public static final String getURLSafeString(IdRep ui) {
    return Base64.encodeBase64URLSafeString(ui.getBytes());
}

From source file:org.i3xx.step.uno.impl.CardCacheImpl.java

/**
 * Serializes the content to JSON/*from  w  w  w. ja  va2 s .  co  m*/
 * 
 * @return The JSON String
 */
public String toJSON() {
    Gson gson = new Gson();
    StringBuffer buf = new StringBuffer();

    buf.append('{');

    buf.append(gson.toJson("buffer"));
    buf.append(':');
    buf.append('[');
    for (int i = 0; i < buffer.size(); i++) {
        if (i > 0)
            buf.append(',');

        String stmt = Base64.encodeBase64URLSafeString(buffer.get(i));
        buf.append(gson.toJson(stmt));
    }
    buf.append(']');

    buf.append('}');

    return buf.toString();
}