Example usage for android.util Base64 DEFAULT

List of usage examples for android.util Base64 DEFAULT

Introduction

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

Prototype

int DEFAULT

To view the source code for android.util Base64 DEFAULT.

Click Source Link

Document

Default values for encoder/decoder flags.

Usage

From source file:Main.java

public static String encode(String binaryData) {
    if (TextUtils.isEmpty(binaryData)) {
        return "";
    }/*from   w ww .j a va2  s . co m*/
    return new String(Base64.encode(binaryData.getBytes(), Base64.DEFAULT));

}

From source file:Main.java

public static byte[] base64EncodeByte(final byte[] data) {
    return Base64.encode(data, Base64.DEFAULT);
}

From source file:Main.java

/**
 * Converts from String to byte array//www .  j  a va2 s  .  c  o  m
 * @param str - The String to be decoded
 * @return - The returned byte array
 */
public static byte[] decode(String str) {
    return Base64.decode(str.getBytes(), Base64.DEFAULT);
}

From source file:Main.java

public static Bitmap base64ToBitmap(String base64Data) {
    byte[] bytes = Base64.decode(base64Data.replaceFirst("data:image/jpeg;base64,", "").trim(), Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static String decodeBase64(String str) throws UnsupportedEncodingException, Base64DataException {
    return new String(Base64.decode(str, Base64.DEFAULT), "UTF-8");

}

From source file:Main.java

public static String decode(String data) throws UnsupportedEncodingException {
    byte[] b = Base64.decode(data.getBytes(ENCODING), Base64.DEFAULT);
    return new String(b, ENCODING);
}

From source file:Main.java

public static String decryptData(String encryptBase64Data, String keyBase64) {
    SecretKeySpec key = new SecretKeySpec(Base64.decode(keyBase64, Base64.DEFAULT), "DES");
    Cipher decipher = null;/*ww  w.  j av a 2 s  .com*/
    try {
        decipher = Cipher.getInstance("DES");
        decipher.init(Cipher.DECRYPT_MODE, key);
        byte[] encryptData = Base64.decode(encryptBase64Data, Base64.DEFAULT);
        return new String(decipher.doFinal(encryptData), "UTF8");
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

public static Bitmap fromBase64(String base64) {
    Bitmap bitmap = null;//from  ww w.j  a  va  2s. c  om
    if (base64 != null) {
        byte[] bytes = Base64.decode(base64, Base64.DEFAULT);
        if (null != bytes) {
            bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        }
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap getBitmapFromBase64(String string) {
    byte[] bitmapArray = null;
    try {//from  w w w.j a  v a2s.  c  o  m
        bitmapArray = Base64.decode(string, Base64.DEFAULT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
}

From source file:Main.java

public static Bitmap base64ToBitmap(String base64) {
    if (base64 != null && !base64.isEmpty()) {
        byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        return decodedByte;
    }/*from  www.j  ava2  s .co  m*/
    return null;
}