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:com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.JSONRecordAdapter.java

/**
 * returns data from json object which was made via translateFromRecord.
 *
 * @param jsonObject the json.//from  w ww  .ja va 2  s  . c  om
 * @throws JSONException
 */
public static ByteBuffer getData(JSONObject jsonObject) throws JSONException {
    return ByteBuffer.wrap(Base64.decode(jsonObject.getString(DATA_FIELD_KEY), Base64.DEFAULT));
}

From source file:bencoding.securely.Converters.java

public static Object deserializeObjectFromString(String objectString) throws Exception {

    ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(
            Base64.decode(objectString, Base64.DEFAULT));
    GZIPInputStream gzipInputStream = new GZIPInputStream(arrayInputStream);
    ObjectInputStream objectInputStream = new ObjectInputStream(gzipInputStream);

    Object object = objectInputStream.readObject();

    objectInputStream.close();//from   w w w .  jav  a  2 s  .  co  m
    gzipInputStream.close();
    arrayInputStream.close();

    return object;
}

From source file:com.orange.oidc.secproxy_service.Token.java

static String getJSON(String token) {
    String ds = null;/*  ww  w  .  j av a 2  s.  c  om*/

    String tokenB64 = null;
    if (token != null) {
        String[] p = token.split("\\.");
        if (p != null && p.length == 3) {
            tokenB64 = p[1];
        }
    }

    if (tokenB64 != null) {
        byte[] decoded = null;
        try {
            decoded = Base64.decode(tokenB64, Base64.URL_SAFE);
            ds = new String(decoded, "UTF-8");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (decoded == null) {
            try {
                decoded = Base64.decode(tokenB64, Base64.DEFAULT);
                ds = new String(decoded, "UTF-8");
            } catch (Exception ee) {
                // TODO Auto-generated catch block
                ee.printStackTrace();
            }
        }
    }
    return ds;
}

From source file:heylee.android.network.JSONParserCustom.java

public static String autoBase64Decode(String CheckString) {
    String BASE64_REGEX = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
    if (CheckString.matches(BASE64_REGEX)) {
        if (CheckString == null || CheckString.isEmpty())
            return "";
        else//from  w w  w.  j  a v  a 2  s. c o  m
            return new String(Base64.decode(Uri.decode(CheckString), 0));
    }
    return CheckString;
}

From source file:com.google.samples.apps.abelana.AbelanaThings.java

public static AbelanaUser start(Context ctx, String atok, String secret) {
    AbelanaUser user = new AbelanaUser();

    String[] part = atok.split("\\.");
    byte[] jb = Base64.decode(part[1], Base64.URL_SAFE);
    String json = new String(jb);
    byte[] half = Base64.decode(secret, Base64.URL_SAFE);
    String halfpw = new String(half);

    try {/*from   w ww  .j av a2s. c  om*/
        JSONObject pojo = new JSONObject(json);
        user.UserID = pojo.getString("UserID");
        user.Exp = pojo.getLong("Exp");
        user.Iat = pojo.getLong("Iat");
    } catch (JSONException e) {
        System.out.println("Abelana User - convert json " + e.toString());
        return null;
    }
    if (storage == null) {
        AbelanaThings at = new AbelanaThings(ctx, halfpw);
    }
    return user;
}

From source file:illab.nabal.util.SecurityHelper.java

/**
 * Decrypt a AES-encrypted message.//from   w  w w. j a  v  a  2s.  co  m
 * 
 * @param encrypted
 * @return String
 * @throws Exception
 */
public static String decipher(String encrypted) throws Exception {
    if (StringHelper.isEmpty(encrypted) == false) {
        Cipher cipher = Cipher.getInstance(AES);
        cipher.init(Cipher.DECRYPT_MODE, SYSTEM_SECRET_KEY_SPEC);
        return new String(cipher.doFinal(Base64.decode(encrypted, Base64.DEFAULT)), HTTP.UTF_8);
    } else {
        return null;
    }
}

From source file:com.royclarkson.springagram.model.ItemResource.java

public void setImage(String imageDataUri) {
    String imageDataString = imageDataUri.substring(imageDataUri.indexOf(",") + 1);
    byte[] imageData = Base64.decode(imageDataString, Base64.DEFAULT);
    Bitmap original = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
    this.image = ThumbnailUtils.extractThumbnail(original, IMAGE_WIDTH, IMAGE_HEIGHT);
    this.thumbnail = ThumbnailUtils.extractThumbnail(original, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static String decryptStringImpl(Context context, final String encryptedText) {
    String plainText = null;/* www. j  ava  2s.  c  om*/
    try {
        final KeyStore keyStore = getKeyStore(context);

        PrivateKey privateKey = (PrivateKey) keyStore.getKey(KEY_ALIAS, null);

        String algorithm = ALGORITHM_OLD;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            algorithm = ALGORITHM;
        }
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.DECRYPT_MODE, privateKey);

        CipherInputStream cipherInputStream = new CipherInputStream(
                new ByteArrayInputStream(Base64.decode(encryptedText, Base64.DEFAULT)), cipher);

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        int b;
        while ((b = cipherInputStream.read()) != -1) {
            outputStream.write(b);
        }
        outputStream.close();
        plainText = outputStream.toString("UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return plainText;
}

From source file:com.knowledgecode.cordova.websocket.SendingTask.java

@Override
public void execute(JSONArray args, CallbackContext ctx) {
    try {//from  w ww .j  av  a2  s  .com
        int id = args.getInt(0);
        String data = args.getString(1);
        boolean binaryString = args.getBoolean(2);
        Connection conn = _map.get(id);

        if (conn != null) {
            if (binaryString) {
                byte[] binary = Base64.decode(data, Base64.NO_WRAP);
                conn.sendMessage(binary, 0, binary.length);
            } else {
                conn.sendMessage(data);
            }
        }
    } catch (Exception e) {
        ctx.error("send");
    }
}

From source file:com.tapchatapp.android.service.GCMReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String messageType = mGCM.getMessageType(intent);
    if (!messageType.equals(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE)) {
        return;/*from   ww  w.j  av a  2 s  .c  om*/
    }

    try {
        byte[] cipherText = Base64.decode(intent.getStringExtra("payload"), Base64.URL_SAFE | Base64.NO_WRAP);
        byte[] iv = Base64.decode(intent.getStringExtra("iv"), Base64.URL_SAFE | Base64.NO_WRAP);

        byte[] key = mPusherClient.getPushKey();
        if (key == null) {
            // I don't think this will ever happen
            throw new Exception("Received push notification before receiving decryption key.");
        }

        JSONObject message = new JSONObject(new String(decrypt(cipherText, key, iv), "UTF-8"));

        Intent broadcastIntent = new Intent(TapchatApp.ACTION_MESSAGE_NOTIFY);
        addExtras(broadcastIntent, message);
        context.sendOrderedBroadcast(broadcastIntent, null);
    } catch (Exception ex) {
        Log.e(TAG, "Error parsing push notification", ex);
    }
}