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:me.schiz.functions.Base64DecodeFunction.java

public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    String str = ((CompoundVariable) values[0]).execute();
    return Base64.decodeBase64(str).toString();
}

From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.CounterRollupSerializationTest.java

@Test
public void testCounterV1RoundTrip() throws IOException {
    BluefloodCounterRollup c0 = new BluefloodCounterRollup().withCount(7442245).withSampleCount(1);
    BluefloodCounterRollup c1 = new BluefloodCounterRollup().withCount(34454722343L).withSampleCount(10);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(Base64.encodeBase64(Serializers.counterRollupInstance.toByteBuffer(c0).array()));
    baos.write("\n".getBytes());
    baos.write(Base64.encodeBase64(Serializers.counterRollupInstance.toByteBuffer(c1).array()));
    baos.write("\n".getBytes());

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    BufferedReader reader = new BufferedReader(new InputStreamReader(bais));

    ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
    BluefloodCounterRollup cc0 = Serializers.serializerFor(BluefloodCounterRollup.class).fromByteBuffer(bb);
    Assert.assertEquals(c0, cc0);//www  . j  av a 2 s. c o  m

    bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
    BluefloodCounterRollup cc1 = Serializers.serializerFor(BluefloodCounterRollup.class).fromByteBuffer(bb);

    Assert.assertEquals(c1, cc1);
    Assert.assertFalse(cc0.equals(cc1));
}

From source file:biopolis.headless.BiopolisManager.java

public List<BiopolisResult<T>> get(Long[] ids) throws SQLException, BiopolisGeneralException {
    List<BiopolisResult<T>> objects = new ArrayList<BiopolisResult<T>>();
    String lista = BiopolisUtilities.toNeo4JArglist(ids);
    if (!lista.isEmpty()) {
        String queryString = " MATCH (n:" + this.nodetype + ") WHERE ID(n) in" + lista
                + "  RETURN ID(n),n.desci";
        try (ResultSet rs = this.pl.getConnNeo4j().createStatement().executeQuery(queryString)) {
            while (rs.next()) {
                String jsonbytes = rs.getString(2);
                String json = new String(Base64.decodeBase64(jsonbytes));
                java.lang.reflect.Type listType = new TypeToken<T>() {
                }.getType();//from   ww w. j av a  2s.c  o  m
                BiopolisResult<T> result = new BiopolisResult<T>();
                result.id = rs.getLong(1);
                result.object = (new Gson()).fromJson(json, listType);
                objects.add(result);
            }
        }
    }
    return objects;
}

From source file:com.google.nigori.common.TypeAdapterByteString.java

@SuppressWarnings("deprecation") // see comment below
@Override/* w ww.  j a  v  a  2s.  c o  m*/
public ByteString deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    byte[] jsonBytes = json.getAsString().getBytes();
    // (drt24) Since android ships with an ancient version of org.apache.commons.codec which
    // overrides any version we ship we have to use old deprecated methods.
    if (Base64.isArrayByteBase64(jsonBytes)) {
        return ByteString.copyFrom(Base64.decodeBase64(jsonBytes));
    } else {
        throw new JsonParseException("JSON element is not correctly base64 encoded.");
    }
}

From source file:Clases.cCifrado.java

public String Desencriptar(String textoEncriptado) {

    String secretKey = "MARSOFT"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {//  w  w w  . ja va  2  s .c  om
        byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");

        Cipher decipher = Cipher.getInstance("DESede");
        decipher.init(Cipher.DECRYPT_MODE, key);

        byte[] plainText = decipher.doFinal(message);

        base64EncryptedString = new String(plainText, "UTF-8");

    } catch (Exception ex) {
    }
    return base64EncryptedString;
}

From source file:com.wso2telco.cryptosystem.AESencrp.java

/**
 * Decrypt./*from  ww w.  j av a 2 s  .  c o  m*/
 *
 * @param encryptedData the encrypted data
 * @return the string
 * @throws Exception the exception
 */
public static String decrypt(String encryptedData) throws Exception {
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.DECRYPT_MODE, key);
    //byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);
    byte[] decordedValue = Base64.decodeBase64(encryptedData.getBytes());
    byte[] decValue = c.doFinal(decordedValue);
    String decryptedValue = new String(decValue);
    return decryptedValue;
}

From source file:com.marintek.isis.wicket.popupbox.applib.PopupWicketBoxSemanticsProvider.java

static Object fromString(String s) {
    final byte[] data = Base64.decodeBase64(s);
    ObjectInputStream ois = null;
    try {/*from  www  . jav a2 s  .  c  om*/
        ois = new ObjectInputStream(new ByteArrayInputStream(data));
        return ois.readObject();
    } catch (IOException e) {
        throw new Base64Serializer.Exception(e);
    } catch (ClassNotFoundException e) {
        throw new Base64Serializer.Exception(e);
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
        } catch (IOException e) {
            throw new Base64Serializer.Exception(e);
        }
    }
}

From source file:net.ftb.util.CryptoUtils.java

/**
 * Method to AES decrypt string if fails, will attempt to use {@link #decryptLegacy(String str, byte[] key)}
 * @param str string to decrypt/*  w ww .  j  a v  a2s  .  c  om*/
 * @param key decryption key key
 * @return decrypted string or "" if legacy fails
 */
public static String decrypt(String str, byte[] key) {
    try {
        Cipher aes = Cipher.getInstance("AES");
        aes.init(Cipher.DECRYPT_MODE, new SecretKeySpec(pad(key), "AES"));
        String s = new String(aes.doFinal(Base64.decodeBase64(str)), "utf8");
        if (s.startsWith("FDT:") && s.length() > 4)
            return s.split(":", 2)[1];//we don't want the decryption test
        else
            return decryptLegacy(str, key);
    } catch (Exception e) {
        Logger.logError("Error Decrypting information, attempting legacy decryption", e);
        return decryptLegacy(str, key);
    }
}

From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscCipher.java

/**
 * /*  ww w  .  j av  a  2s.  co m*/
 * 
 * @param data ? ?
 * @return ? ?
 */
public static String decode(String data) {
    try {
        Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte d[] = cipher.doFinal(Base64.decodeBase64(data.getBytes("UTF-8")));
        return replaceChar(new String(d));
    } catch (NoSuchAlgorithmException e) {
        System.err.print(XNDiscUtils.printStackTrace(e));
    } catch (NoSuchPaddingException e) {
        System.err.print(XNDiscUtils.printStackTrace(e));
    } catch (IOException e) {
        System.err.print(XNDiscUtils.printStackTrace(e));
    } catch (InvalidKeyException e) {
        System.err.print(XNDiscUtils.printStackTrace(e));
    } catch (IllegalBlockSizeException e) {
        System.err.print(XNDiscUtils.printStackTrace(e));
    } catch (BadPaddingException e) {
        System.err.print(XNDiscUtils.printStackTrace(e));
    }
    return null;
}

From source file:com.glaf.mail.util.MailUtils.java

public static String getFromBASE64(String base64String) {
    if (base64String == null) {
        return null;
    }/*from  w ww  . java  2  s  . c  o m*/
    try {
        byte[] b = Base64.decodeBase64(base64String);
        return new String(b);
    } catch (Exception e) {
        return null;
    }
}