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

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

Introduction

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

Prototype

public static byte[] decodeBase64(final byte[] base64Data) 

Source Link

Document

Decodes Base64 data into octets

Usage

From source file:com.tesora.dve.common.PECryptoUtils.java

public static String decrypt(String str) throws PEException {
    if (StringUtils.isBlank(str))
        return str;

    try {// ww w  . java 2  s . c  o m
        Cipher cipher = createCrypter(Cipher.DECRYPT_MODE);

        return new String(cipher.doFinal(Base64.decodeBase64(str)), "UTF8");
    } catch (Exception e) {
        throw new PEException("Failed to decrypt '" + str + "'", e);
    }
}

From source file:com.ggasoftware.uitest.utils.ScreenShotMaker.java

/**
 * create screenshot on remote machine//from   ww w  .  java 2s .co m
 *
 * @param id - name output png file
 * @return full path
 */
public static String takeScreenshotRemote(String id) {
    String sId = id;
    String base64Screenshot;
    if (hasTake) {
        if (isDirectoryCorrect()) {
            String name = String.format("%s.png",
                    DateUtil.now(new SimpleDateFormat("HH_mm_ss-sss").toPattern()));
            try {
                TakesScreenshot tsDriver;
                tsDriver = (TakesScreenshot) WebDriverWrapper.getDriver();
                base64Screenshot = tsDriver.getScreenshotAs(OutputType.BASE64);

                byte[] decodedScreenshot = Base64.decodeBase64(base64Screenshot.getBytes());
                File file = new File(ScreenShotMaker.path + name);
                try (FileOutputStream fos = new FileOutputStream(file)) {
                    fos.write(decodedScreenshot);
                }
                if (TestBaseWebDriver.allure) {
                    saveScreenshot(decodedScreenshot);
                }
                if (TestBaseWebDriver.reportportal) {
                    ReporterNGExt.log4j(new ReportPortalMessage(file, id));
                }
            } catch (WebDriverException | IOException e) {
                sId += String.format("  [%s when making screenshot(webdriver: %s)]", e.toString(),
                        WebDriverWrapper.getDriver());
                ReporterNGExt.log4jError(String.format("%s when making screenshot(webdriver: %s; file: %s%s) ",
                        e.toString(), WebDriverWrapper.getDriver(), ScreenShotMaker.path, name));
            }
            return dir + name + "|" + sId;
        }
        ReporterNGExt.log4jError(String.format("Incorrect directory screenshot directory: %s", path));
        return String.format("Incorrect directory screenshot directory: %s", path);
    } else {
        return id;
    }
}

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

/**
 *
 * @param b64data/*from  w  w w . j  a v a  2 s .c  o  m*/
 * @return
 */
public String base64toHex(String b64data) {
    String hexDataString = Hex.encodeHexString(Base64.decodeBase64(b64data));
    return hexDataString;
}

From source file:cn.vlabs.duckling.aone.client.impl.EmailNameEncoding.java

private synchronized void initClientKey() {
    if (key == null) {
        InputStream in = EmailNameEncoding.class.getResourceAsStream("ddlclientkey");
        try {//from   w ww .ja  v a2s. c o m
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            String keys = reader.readLine();
            reader.close();
            key = Base64.decodeBase64(keys);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("??utf-8?", e);
        } catch (IOException e) {
            throw new RuntimeException("?ddlclientkey", e);
        }
    }
}

From source file:de.nrw.hbz.deepzoomer.fileUtil.FileUtil.java

/**
 * <p><em>Title: Create a temporary File from a Base64 encoded byteStream</em></p>
 * <p>Description: Method creates a temporary file from the bytestream 
 * representing the orginal PDF, that should be converted</p>
 * //from ww  w . ja v a2 s .c  o m
 * @param stream <code>String</code> 
 * @return <code>String</code> Filename of newly created temporary File
 */
public static String saveStreamToTempFile(String fileName, String stream) {
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    try {
        //System.out.println("Base64 kodierter Stream: " + stream.length());
        inputFile = new File(Configuration.getTempDirPath() + fileName);
        log.debug(Configuration.getTempDirPath());
        fos = new FileOutputStream(inputFile);
        bos = new BufferedOutputStream(fos);
        bos.write(Base64.decodeBase64(stream.getBytes("UTF-8")));

    } catch (IOException ioExc) {
        log.error(ioExc);
    } finally {
        if (bos != null) {
            try {
                bos.close();
            } catch (IOException ioExc) {
                log.error(ioExc);
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException ioExc) {
                log.error(ioExc);
            }
        }
    }
    log.debug("File-Size: " + inputFile.length());
    return inputFile.getName();
}

From source file:com.cloud.utils.ssh.SSHKeysHelper.java

public static String getPublicKeyFromKeyMaterial(String keyMaterial) {
    if (!keyMaterial.contains(" "))
        keyMaterial = new String(Base64.decodeBase64(keyMaterial.getBytes()));

    if (!keyMaterial.startsWith("ssh-rsa") || !keyMaterial.contains(" "))
        return null;

    String[] key = keyMaterial.split(" ");
    if (key.length < 2)
        return null;

    return key[0].concat(" ").concat(key[1]);
}

From source file:com.cliqset.magicsig.MagicKey.java

public MagicKey(String type, String armoredN, String armoredE) {
    if (type == null) {
        throw new IllegalArgumentException("type must not be null");
    }//w w w.j  av a2 s.c  om
    if (armoredN == null) {
        throw new IllegalArgumentException("N must not be null");
    }
    if (armoredE == null) {
        throw new IllegalArgumentException("E must not be null");
    }
    this.setType(type);
    this.setN(Base64.decodeBase64(armoredN));
    this.setE(Base64.decodeBase64(armoredE));
}

From source file:ch.bfh.evoting.verifier.entities.XMLElement.java

public ch.bfh.unicrypt.math.algebra.general.interfaces.Element getValue(Group group) {
    return group.getElementFrom(ByteTree.getInstanceFrom(ByteArray.getInstance(Base64.decodeBase64(value))));
}

From source file:it.latraccia.pkcs11.reader.util.AESUtil.java

public static String decryptString(String encryptedText, String password)
        throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
        InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
    String decrypted = null;/*from   w  w  w  . ja  va 2 s  . c o  m*/
    byte[] key = password.getBytes();
    if (key.length != 16) {
        throw new IllegalArgumentException("Invalid key size.");
    }
    byte[] value = Base64.decodeBase64(encryptedText);

    // Decrypt with AES/CBC/PKCS5Padding
    SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(new byte[16]));
    byte[] original = cipher.doFinal(value);
    decrypted = new String(original);

    return decrypted;
}

From source file:com.muk.services.processor.BasicAuthPrincipalProcessor.java

@Override
public void process(Exchange exchange) throws Exception {
    @SuppressWarnings("unchecked")
    final List<Header> httpHeaders = exchange.getIn().getHeader("org.restlet.http.headers", List.class);

    String userpass = "bad:creds";
    for (final Header header : httpHeaders) {
        if (header.getName().toLowerCase().equals(HttpHeaders.AUTHORIZATION.toLowerCase())) {
            userpass = new String(Base64.decodeBase64(
                    (StringUtils.substringAfter(header.getValue(), " ").getBytes(StandardCharsets.UTF_8))),
                    StandardCharsets.UTF_8);
            break;
        }/*from www .  j a  va  2s  .c  o  m*/
    }

    final String[] tokens = userpass.split(":");

    // create an Authentication object
    // build a new bearer token type
    final UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(tokens[0],
            tokens[1]);

    // wrap it in a Subject
    final Subject subject = new Subject();
    subject.getPrincipals().add(authToken);

    // place the Subject in the In message
    exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject);
}