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:com.arm.connector.bridge.core.Utils.java

public static String createHash(String data) {
    try {/* w  w  w.ja  va 2s. com*/
        if (data == null) {
            return "none";
        }
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] digest = md.digest(data.getBytes());
        String hex = Hex.encodeHexString(digest);
        return Base64.encodeBase64URLSafeString(hex.getBytes());
    } catch (NoSuchAlgorithmException ex) {
        return "none";
    }
}

From source file:manager.doCreateToy.java

public String encodeImage(byte[] imageByteArray) {
    return Base64.encodeBase64URLSafeString(imageByteArray);
}

From source file:de.huxhorn.sulky.plist.impl.PropertyListWriter.java

private void writeData(XMLStreamWriter writer, byte[] data) throws XMLStreamException {
    StaxUtilities.writeSimpleTextNode(writer, null, null, DATA_NODE, Base64.encodeBase64URLSafeString(data));
}

From source file:gov.nih.nci.rembrandt.util.IGVHelper.java

private void generateFileName(String sessionId, String rembrandtUser) {
    igvFilePath = System.getProperty("gov.nih.nci.rembrandt.data_directory");
    if (rembrandtUser != null) {
        this.rembrandtUser = rembrandtUser;
        this.encodedUser = Base64.encodeBase64URLSafeString(rembrandtUser.getBytes());
    }/*w w  w.j  a va2 s  .  c  o  m*/

    //get the clinical file path
    if (igvFilePath != null && clinicalFile != null) {
        igvClinicalFileName = igvFilePath + File.separator + clinicalFile;
    }
    //get the session file path
    if (igvFilePath != null) {
        igvFilePath = igvFilePath + File.separator + sessionId + File.separator;
    }

    /*
     * Creates the session image temp folder if the
     * folder does not already exist
     */
    File dir = new File(igvFilePath);
    if (!dir.exists()) {
        dir.mkdir();
    }

    //the actual unique file name
    String uniqueName = createUniqueFileName();

    igvFileName = uniqueName + ".xml";

    igvCopyNumberFileName = uniqueName + "_cn" + ".seg";

}

From source file:com.google.gerrit.httpd.auth.oauth.OAuthSession.java

private static String generateRandomState() {
    byte[] state = new byte[32];
    randomState.nextBytes(state);//  w  w  w  .jav a 2s.c om
    return Base64.encodeBase64URLSafeString(state);
}

From source file:fr.zcraft.zbanque.network.PacketSender.java

private static void authenticateRequest(HttpURLConnection connection) {
    String user = Config.WEBSERVICE.USERNAME.get();
    String pass = Config.WEBSERVICE.PASSWORD.get();

    if (user == null || user.isEmpty())
        return;//  w  w w . j ava2  s  .c om

    if (pass == null)
        pass = "";

    String authToken = Base64.encodeBase64URLSafeString((user + ":" + pass).getBytes());

    connection.setRequestProperty("Authorization", "Basic " + authToken);
}

From source file:io.stallion.utils.GeneralUtils.java

/**
 * Generates a random string using the SecureRandom module, of the given length,
 * using URL safe base64 characters/* w  w  w  .  j  a  va 2 s. co m*/
 *
 * @param length
 * @return
 */
public static String secureRandomToken(int length) {
    SecureRandom random = new SecureRandom();
    byte bytes[] = new byte[length * 4];
    random.nextBytes(bytes);
    String s = Base64.encodeBase64URLSafeString(bytes).substring(0, length);
    return s;
}

From source file:com.dell.asm.asmcore.asmmanager.util.discovery.DeviceTypeCheckUtil.java

private static String encodeCredentials(String username, String password) {
    return "Basic {"
            + Base64.encodeBase64URLSafeString((username + ":" + password).getBytes(Charset.forName("UTF-8")))
            + "}";
}

From source file:com.urbancode.terraform.main.Main.java

/**
 * Initializes Terraform so it can execute the given commands.
 * Here is the order of operations:// w w  w .  j  a v  a 2  s.c  om
 * Parses the credentials file and verifies the given credentials.
 * Generates a random string for this environment, which is appended to the output xml file.
 * Parses the xml file.
 * Runs the specified command (create, destroy, etc).
 * @throws XmlParsingException
 * @throws IOException
 * @throws CredentialsException
 * @throws CreationException
 * @throws DestructionException
 * @throws RestorationException
 */
public void execute() throws XmlParsingException, IOException, CredentialsException, CreationException,
        DestructionException, RestorationException {
    TerraformContext context = null;
    try {
        // parse xml and set context
        context = parseContext(inputXmlFile);

        Credentials credentials = parseCredentials(credsFile);

        context.setCredentials(credentials);
        if (AllowedCommands.CREATE.getCommandName().equalsIgnoreCase(command)) {
            // create new file if creating a new environment
            UUID uuid = UUID.randomUUID();
            //convert uuid to base 62 (allowed chars: 0-9 a-z A-Z)
            ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
            bb.putLong(uuid.getMostSignificantBits());
            bb.putLong(uuid.getLeastSignificantBits());
            String suffix = Base64.encodeBase64URLSafeString(bb.array());
            suffix = suffix.replaceAll("-", "Y");
            suffix = suffix.replaceAll("_", "Z");
            suffix = suffix.substring(0, 4);
            if (context.getEnvironment() != null) {
                context.getEnvironment().addSuffixToEnvName(suffix);
                log.debug("UUID for env " + context.getEnvironment().getName() + " is " + suffix);
            } else {
                throw new NullPointerException("No environment on context!");
            }

            String name = context.getEnvironment().getName();
            log.debug("Output filename = " + name);
            outputXmlFile = new File("env-" + name + ".xml");

            log.debug("Calling create() on context");
            context.create();
        } else if (AllowedCommands.DESTROY.getCommandName().equalsIgnoreCase(command)) {
            String suffix = parseSuffix(context.getEnvironment().getName());
            context.getEnvironment().setSuffix(suffix);
            log.debug("found suffix " + suffix);
            // write out instance failure regardless of success or failure
            outputXmlFile = inputXmlFile;
            log.debug("Calling destroy() on context");
            context.destroy();
        } else if (AllowedCommands.SUSPEND.getCommandName().equalsIgnoreCase(command)) {
            outputXmlFile = inputXmlFile;
            log.debug("Calling restore() on context");
            log.info("Attempting to suspend power on all instances/VMs in the environment.");
            context.restore();
            if (context instanceof ContextVmware) {
                SuspendCommand newCommand = new SuspendCommand((ContextVmware) context);
                newCommand.execute();
            } else if (context instanceof ContextAWS) {
                com.urbancode.terraform.commands.aws.SuspendCommand newCommand = new com.urbancode.terraform.commands.aws.SuspendCommand(
                        (ContextAWS) context);
                newCommand.execute();
            } else {
                log.warn("Could not resolve context to call command \"" + command + "\"");
            }
        } else if (AllowedCommands.RESUME.getCommandName().equalsIgnoreCase(command)) {
            outputXmlFile = inputXmlFile;
            log.debug("Calling restore() on context");
            context.restore();
            log.info("Attempting to power on all instances/VMs in the environment.");
            if (context instanceof ContextVmware) {
                ResumeCommand newCommand = new ResumeCommand((ContextVmware) context);
                newCommand.execute();
            } else if (context instanceof ContextAWS) {
                com.urbancode.terraform.commands.aws.ResumeCommand newCommand = new com.urbancode.terraform.commands.aws.ResumeCommand(
                        (ContextAWS) context);
                newCommand.execute();
            }

            else {
                log.warn("Could not resolve context to call command \"" + command + "\"");
            }
        } else if (AllowedCommands.TAKE_SNAPSHOT.getCommandName().equalsIgnoreCase(command)) {
            outputXmlFile = inputXmlFile;
            log.debug("Calling restore() on context");
            context.restore();
            log.info("Attempting to take snapshots of all instances/VMs in the environment.");
            if (context instanceof ContextVmware) {
                TakeSnapshotCommand newCommand = new TakeSnapshotCommand((ContextVmware) context);
                newCommand.execute();
            } else if (context instanceof ContextAWS) {
                log.warn("Taking snapshots is not currently supported with Terraform and AWS.");
            }

            else {
                log.warn("Could not resolve context to call command \"" + command + "\"");
            }
        }
    } catch (ParserConfigurationException e1) {
        throw new XmlParsingException("ParserConfigurationException: " + e1.getMessage(), e1);
    } catch (SAXException e2) {
        throw new XmlParsingException("SAXException: " + e2.getMessage(), e2);
    } finally {
        if (context != null && context.doWriteContext() && outputXmlFile != null) {
            log.debug("Writing context out to " + outputXmlFile);
            writeEnvToXml(outputXmlFile, context);
        }
    }
}

From source file:net.oauth.jsontoken.JsonToken.java

private String getSignature() throws SignatureException {
    if (signature != null && !signature.isEmpty()) {
        return signature;
    }//  www .java  2 s.c  om

    if (signer == null) {
        throw new SignatureException("can't sign JsonToken with signer.");
    }
    String signature;
    // now, generate the signature
    AsciiStringSigner asciiSigner = new AsciiStringSigner(signer);
    signature = Base64.encodeBase64URLSafeString(asciiSigner.sign(baseString));

    return signature;
}