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:ch.ethz.twimight.net.opportunistic.ScanningService.java

/**
 * Creates content values for a User from a JSON object TODO: Move this to
 * where it belongs//from  ww w. j  a  va 2s .c  o  m
 * 
 * @param o
 * @return
 * @throws JSONException
 */
protected ContentValues getUserCV(JSONObject o) throws JSONException {

    // create the content values for the user
    ContentValues cv = new ContentValues();
    String screenName = null;

    if (o.has(TwitterUsers.COL_SCREEN_NAME)) {
        screenName = o.getString(TwitterUsers.COL_SCREEN_NAME);
        cv.put(TwitterUsers.COL_SCREEN_NAME, o.getString(TwitterUsers.COL_SCREEN_NAME));
    }

    if (o.has(TwitterUsers.JSON_FIELD_PROFILE_IMAGE) && screenName != null) {
        InternalStorageHelper helper = new InternalStorageHelper(getBaseContext());
        byte[] image = Base64.decode(o.getString(TwitterUsers.JSON_FIELD_PROFILE_IMAGE), Base64.DEFAULT);
        helper.writeImage(image, screenName);
        String profileImageUri = Uri.fromFile(new File(getFilesDir(), screenName)).toString();
        Log.d(TAG, "storing profile image at: " + profileImageUri);
        cv.put(TwitterUsers.COL_PROFILE_IMAGE_URI, profileImageUri);
    }

    if (o.has(Tweets.COL_USER_TID)) {
        cv.put(TwitterUsers.COL_TWITTER_USER_ID, o.getLong(Tweets.COL_USER_TID));

    }
    cv.put(TwitterUsers.COL_IS_DISASTER_PEER, 1);

    return cv;
}

From source file:com.supremainc.biostar2.user.UserModifyFragment.java

private void setView() {
    if (mLayout == null) {
        return;/*from w  w w.j av  a2 s.  com*/
    }
    mLayout.setUserID(mUserInfo.user_id);
    mLayout.setUserName(mUserInfo.name);
    mLayout.showPin(mUserInfo.pin_exist);

    if (!mIsNewUser) {
        mLayout.setNewUser(false);
        if (mPermissionDataProvider.getPermission(PERMISSION_MODULE.MONITORING, false)) {
            mLayout.showUserViewLog(true);
        } else {
            mLayout.showUserViewLog(false);
        }
    } else {
        mLayout.setNewUser(true);
    }

    if (mUserInfo.name != null) {

    }
    mLayout.setUserName(mUserInfo.name);
    mLayout.setEmail(mUserInfo.email);
    mLayout.setTelephone(mUserInfo.phone_number);
    mLayout.setLoginID(mUserInfo.login_id);
    setPermission();

    if (mUserInfo.password_exist || (mPasswordData != null && !mPasswordData.isEmpty())) {
        mLayout.setPassword(getString(R.string.password_display));
    } else {
        mLayout.setPassword("");
    }

    if (mUserInfo.user_group != null) {
        mLayout.setUserGroup(mUserInfo.user_group.name);
        mLayout.setUserGroupID(mUserInfo.user_group.id);
    } else {
        //  mLayout.setUserGroup(getString(R.string.all_users));
        mLayout.setUserGroupID(String.valueOf(1));
    }
    if (mUserInfo.isActive()) {
        mLayout.setStatus(getString(R.string.status) + " " + getString(R.string.active));
    } else {
        mLayout.setStatus(getString(R.string.status) + " " + getString(R.string.inactive));
    }
    mStatusSwitch = mLayout.getStatusSwitchView();
    mStatusSwitch.init(getActivity(), new OnChangeListener() {
        @Override
        public void onChange(boolean on) {
            if (BuildConfig.DEBUG) {
                Log.e(TAG, "status :" + on);
            }
            if (on) {
                mUserInfo.setActive(true);
                mLayout.setStatus(getString(R.string.status) + " " + getString(R.string.active));
            } else {
                mUserInfo.setActive(false);
                mLayout.setStatus(getString(R.string.status) + " " + getString(R.string.inactive));
            }
        }
    }, mUserInfo.isActive());
    mStatusSwitch.setSwitch(mUserInfo.isActive());
    mLayout.setDateStart(mUserInfo.getTimeFormmat(mTimeConvertProvider, User.UserTimeType.start_datetime,
            TimeConvertProvider.DATE_TYPE.FORMAT_DATE));
    mLayout.setDateEnd(mUserInfo.getTimeFormmat(mTimeConvertProvider, User.UserTimeType.expiry_datetime,
            TimeConvertProvider.DATE_TYPE.FORMAT_DATE));
    setAccessGroupCount();
    setFingerCount();
    setCardCount();

    mPinSwitch = mLayout.getPinSwitchView();

    if (mUserInfo.pin_exist || (mPinData != null && !mPinData.isEmpty())) {
        mLayout.setPin(getString(R.string.password_display));
    } else {
        mLayout.setPin("");
    }
    mPinSwitch.init(getActivity(), new OnChangeListener() {
        @Override
        public void onChange(boolean on) {
            if (BuildConfig.DEBUG) {
                Log.e(TAG, "pin :" + on);
            }
            if (on) {
                showPinPasswodPopup();
            } else {
                mLayout.setPin("");
                mPinData = "";
            }
        }
    }, (mUserInfo.pin_exist || (mPinData != null && !mPinData.isEmpty())));
    mPinSwitch.setSwitch((mUserInfo.pin_exist || (mPinData != null && !mPinData.isEmpty())));
    mLayout.setUserPhotoDefault();
    if (mRbmp != null) {
        mLayout.setUserPhoto(mRbmp);
    } else if (bmp != null) {
        mRbmp = ImageUtil.getRoundedBitmap(bmp, false);
        mLayout.setUserPhoto(mRbmp);
    } else {
        if (mUserInfo.photo != null && !mUserInfo.photo.isEmpty()) {
            byte[] photoByte = Base64.decode(mUserInfo.photo, 0);
            bmp = ImageUtil.byteArrayToBitmap(photoByte);
            if (bmp != null) {
                mBlurBmp = ImageUtil.fastBlur(bmp, 32);
                mLayout.setBlurBackGroud(mBlurBmp);
                mRbmp = ImageUtil.getRoundedBitmap(bmp, false);
                mLayout.setUserPhoto(mRbmp);
            }
        }
    }
    isExistImageCheck();
}

From source file:csh.cryptonite.Cryptonite.java

public static String decrypt(String value, Context context) throws RuntimeException {
    try {//  w  ww  . j a v  a 2s.  c  om
        final byte[] bytes = value != null ? Base64.decode(value, Base64.DEFAULT) : new byte[0];
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey key = keyFactory.generateSecret(new PBEKeySpec(jniFullPw().toCharArray()));
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
        pbeCipher.init(Cipher.DECRYPT_MODE, key,
                new PBEParameterSpec(Settings.Secure
                        .getString(context.getContentResolver(), Settings.Secure.ANDROID_ID).getBytes("utf-8"),
                        20));
        return new String(pbeCipher.doFinal(bytes), "utf-8");

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.cryptsecure.Utility.java

/**
 * Convert BASE64 to string.// w  ww . ja va2 s  .  co m
 * 
 * @param encodedString
 *            the encoded string
 * @return the string
 */
public static String convertBASE64ToString(String encodedString) {
    return new String(Base64.decode(encodedString.getBytes(), Base64.DEFAULT));
}

From source file:org.cryptsecure.Utility.java

/**
 * Load drawable image from a BASE64 encoded String.
 * //from  ww  w.j av a 2 s. c om
 * @param encodedImage
 *            the encoded image
 * @return the drawable
 */
public static Drawable loadDrawableFromBASE64String(String encodedImage) {
    byte[] imageBytes = Base64.decode(encodedImage.getBytes(), Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(imageBytes);
    Drawable drawable = Drawable.createFromStream(byteArrayInputStream, "attachment");
    return drawable;
}

From source file:org.cryptsecure.Utility.java

/**
 * Load a bitmap image from a BASE64 encoded String.
 * /* www.  ja v  a2  s .com*/
 * @param context
 *            the context
 * @param encodedImage
 *            the encoded image
 * @return the bitmap
 */
public static Bitmap loadImageFromBASE64String(Context context, String encodedImage) {
    byte[] imageBytes = Base64.decode(encodedImage.getBytes(), Base64.DEFAULT);
    return getBitmapFromBytes(imageBytes);
}

From source file:com.android.launcher3.Utilities.java

public static String decrypt(String input) {
    return new String(Base64.decode(input, Base64.CRLF));
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeApplicationMessageFromJSON(UUID uuid, JSONArray jsonArray) {
    ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        try {//from w  w w  .  j  a v  a  2  s .  c o  m
            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            String type = (String) jsonObject.get("type");
            int key = jsonObject.getInt("key");
            int length = jsonObject.getInt("length");
            switch (type) {
            case "uint":
            case "int":
                if (length == 1) {
                    pairs.add(new Pair<>(key, (Object) (byte) jsonObject.getInt("value")));
                } else if (length == 2) {
                    pairs.add(new Pair<>(key, (Object) (short) jsonObject.getInt("value")));
                } else {
                    if (type.equals("uint")) {
                        pairs.add(new Pair<>(key, (Object) (int) (jsonObject.getInt("value") & 0xffffffffL)));
                    } else {
                        pairs.add(new Pair<>(key, (Object) jsonObject.getInt("value")));
                    }
                }
                break;
            case "string":
                pairs.add(new Pair<>(key, (Object) jsonObject.getString("value")));
                break;
            case "bytes":
                byte[] bytes = Base64.decode(jsonObject.getString("value"), Base64.NO_WRAP);
                pairs.add(new Pair<>(key, (Object) bytes));
                break;
            }
        } catch (JSONException e) {
            return null;
        }
    }

    return encodeApplicationMessagePush(ENDPOINT_APPLICATIONMESSAGE, uuid, pairs);
}

From source file:com.android.launcher3.Utilities.java

public static Bitmap loadBitmapPref(Activity activity, String packageName) {
    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(activity);
    String previouslyEncodedImage = shre.getString(packageName, "");

    if (!previouslyEncodedImage.equalsIgnoreCase("")) {
        byte[] b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
        return bitmap;
    }/* w w  w . ja v  a 2 s  .com*/
    return null;
}

From source file:dev.ukanth.ufirewall.Api.java

/**
 * Decrypt the password/*  w w w .  ja va 2s. c  o  m*/
 * @param key
 * @param data
 * @return
 */
public static String unhideCrypt(String key, String data) {
    if (key == null || data == null)
        return null;

    String decryptStr = null;
    try {
        byte[] dataBytes = Base64.decode(data, base64Mode);
        DESKeySpec desKeySpec = new DESKeySpec(key.getBytes(charsetName));
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(algorithm);
        SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        byte[] dataBytesDecrypted = (cipher.doFinal(dataBytes));
        decryptStr = new String(dataBytesDecrypted);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
    return decryptStr;
}