Example usage for android.util Base64 decode

List of usage examples for android.util Base64 decode

Introduction

In this page you can find the example usage for android.util Base64 decode.

Prototype

public static byte[] decode(byte[] input, int flags) 

Source Link

Document

Decode the Base64-encoded data in input and return the data in a new byte array.

Usage

From source file:Main.java

public static String encrypt(String data, String key) throws Exception {
    try {/*from  w  w w. j  a  v a 2 s  .c o  m*/
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        byte[] base64Key = Base64.decode(key, Base64.DEFAULT);
        SecretKeySpec keyspec = new SecretKeySpec(base64Key, "AES");
        cipher.init(Cipher.ENCRYPT_MODE, keyspec);
        byte[] encrypted = cipher.doFinal(data.getBytes("UTF-8"));
        return Base64.encodeToString(encrypted, Base64.DEFAULT);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static List String2SceneList(String SceneListString) throws IOException, ClassNotFoundException {

    byte[] mobileBytes = Base64.decode(SceneListString.getBytes(), Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(mobileBytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    List SceneList = (List) objectInputStream.readObject();
    objectInputStream.close();//w ww  .j a va2 s .com

    return SceneList;
}

From source file:Main.java

public static byte[] encrypt2(byte[] data, String key) throws Exception {
    try {/*from   w w  w  .  j av  a2  s.c o m*/
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        byte[] base64Key = Base64.decode(key, Base64.DEFAULT);
        SecretKeySpec keyspec = new SecretKeySpec(base64Key, "AES");
        cipher.init(Cipher.ENCRYPT_MODE, keyspec);
        byte[] encrypted = cipher.doFinal(data);
        return encrypted;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static byte[] desEncrypt(byte[] data, String key) throws Exception {
    try {/*from  w  w w . j a  v a2 s  .  c  o  m*/
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        byte[] base64Key = Base64.decode(key, Base64.DEFAULT);
        SecretKeySpec keyspec = new SecretKeySpec(base64Key, "AES");
        cipher.init(Cipher.DECRYPT_MODE, keyspec);
        byte[] original = cipher.doFinal(data);
        return original;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Bitmap base64StringToBitmap(String str) {
    if (str == null) {
        return null;
    }/*  ww  w .j  av  a2  s . com*/
    byte[] bytes;
    bytes = Base64.decode(str, Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static Bitmap getBitmapFromBase64(String base64Str) {

    if (TextUtils.isEmpty(base64Str)) {
        return null;
    }//  www .j  av a 2 s .  co m

    byte[] bytes = Base64.decode(base64Str, Base64.NO_WRAP);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static Bitmap getImage(String body) {
    int index = TAG_IMAGE.length();
    body = body.substring(index);//www.  j  a  v a 2  s  .  com
    byte[] imageData = Base64.decode(body, Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

}

From source file:Main.java

public static Bitmap bitmapFromBase64(String base64Str) {
    if (TextUtils.isEmpty(base64Str)) {
        return null;
    } else {//www  .  j a  v  a2  s  .  c  om
        byte[] bytes = Base64.decode(base64Str, Base64.NO_WRAP);
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    }
}

From source file:Main.java

/**
 * Decodes the base64 string into byte array
 * /*www.ja  va2s .  c o m*/
 * @param imageDataString
 *            - a {@link java.lang.String}
 * @return byte array
 */
private static byte[] decodeFile(String imageDataString) throws IllegalArgumentException {
    return Base64.decode(imageDataString, Base64.DEFAULT);
}

From source file:Main.java

public static Object toObject(String base64str) {
    Object obj = null;/*from w w  w.j  a va  2s .co  m*/
    try {
        obj = toObject(Base64.decode(base64str, Base64.DEFAULT));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return obj;
}