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.pimp.companionforband.activities.main.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    sContext = getApplicationContext();/*from   ww w  .j  a va2 s . com*/
    sActivity = this;

    sharedPreferences = getApplicationContext().getSharedPreferences("MyPrefs", 0);
    editor = sharedPreferences.edit();

    bandSensorData = new BandSensorData();

    mDestinationUri = Uri.fromFile(new File(getCacheDir(), SAMPLE_CROPPED_IMAGE_NAME));

    SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;

    if (!checkCameraPermission(true))
        requestCameraPermission(true);
    if (!checkCameraPermission(false))
        requestCameraPermission(false);

    FiveStarsDialog fiveStarsDialog = new FiveStarsDialog(this, "pimplay69@gmail.com");
    fiveStarsDialog.setTitle(getString(R.string.rate_dialog_title))
            .setRateText(getString(R.string.rate_dialog_text)).setForceMode(false).setUpperBound(4)
            .setNegativeReviewListener(this).showAfter(5);

    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    mTracker = application.getDefaultTracker();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            String name;
            switch (position) {
            case 0:
                name = "THEME";
                break;
            case 1:
                name = "SENSORS";
                break;
            case 2:
                name = "EXTRAS";
                break;
            default:
                name = "CfB";
            }

            mTracker.setScreenName("Image~" + name);
            mTracker.send(new HitBuilders.ScreenViewBuilder().build());

            logSwitch = (Switch) findViewById(R.id.log_switch);
            backgroundLogSwitch = (Switch) findViewById(R.id.backlog_switch);
            logStatus = (TextView) findViewById(R.id.logStatus);
            backgroundLogStatus = (TextView) findViewById(R.id.backlogStatus);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    Drawable headerBackground = null;
    String encoded = sharedPreferences.getString("me_tile_image", "null");
    if (!encoded.equals("null")) {
        byte[] imageAsBytes = Base64.decode(encoded.getBytes(), Base64.DEFAULT);
        headerBackground = new BitmapDrawable(
                BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
    }

    AccountHeader accountHeader = new AccountHeaderBuilder().withActivity(this).withCompactStyle(true)
            .withHeaderBackground((headerBackground == null) ? getResources().getDrawable(R.drawable.pipboy)
                    : headerBackground)
            .addProfiles(new ProfileDrawerItem()
                    .withName(sharedPreferences.getString("device_name", "Companion For Band"))
                    .withEmail(sharedPreferences.getString("device_mac", "pimplay69@gmail.com"))
                    .withIcon(getResources().getDrawable(R.drawable.band)))
            .build();

    result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withActionBarDrawerToggleAnimated(true)
            .withAccountHeader(accountHeader)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(getString(R.string.drawer_cloud))
                            .withIcon(GoogleMaterial.Icon.gmd_cloud).withIdentifier(1),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName(getString(R.string.rate))
                            .withIcon(GoogleMaterial.Icon.gmd_rate_review).withIdentifier(2),
                    new PrimaryDrawerItem().withName(getString(R.string.feedback))
                            .withIcon(GoogleMaterial.Icon.gmd_feedback).withIdentifier(3),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName(getString(R.string.share))
                            .withIcon(GoogleMaterial.Icon.gmd_share).withIdentifier(4),
                    new PrimaryDrawerItem().withName(getString(R.string.other))
                            .withIcon(GoogleMaterial.Icon.gmd_apps).withIdentifier(5),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName(getString(R.string.report))
                            .withIcon(GoogleMaterial.Icon.gmd_bug_report).withIdentifier(6),
                    new PrimaryDrawerItem().withName(getString(R.string.translate))
                            .withIcon(GoogleMaterial.Icon.gmd_translate).withIdentifier(9),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName(getString(R.string.support))
                            .withIcon(GoogleMaterial.Icon.gmd_attach_money).withIdentifier(7),
                    new PrimaryDrawerItem().withName(getString(R.string.aboutLib))
                            .withIcon(GoogleMaterial.Icon.gmd_info).withIdentifier(8))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    boolean flag;
                    if (drawerItem != null) {
                        flag = true;
                        switch ((int) drawerItem.getIdentifier()) {
                        case 1:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Cloud").build());

                            if (!sharedPreferences.getString("access_token", "hi").equals("hi"))
                                startActivity(new Intent(getApplicationContext(), CloudActivity.class));
                            else
                                startActivity(new Intent(getApplicationContext(), WebviewActivity.class));
                            break;
                        case 2:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Rate and Review").build());
                            String MARKET_URL = "https://play.google.com/store/apps/details?id=";
                            String PlayStoreListing = getPackageName();
                            Intent rate = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(MARKET_URL + PlayStoreListing));
                            startActivity(rate);
                            break;
                        case 3:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Feedback").build());
                            final StringBuilder emailBuilder = new StringBuilder();
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("mailto:pimplay69@gmail.com"));
                            intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name));

                            emailBuilder.append("\n \n \nOS Version: ").append(System.getProperty("os.version"))
                                    .append("(").append(Build.VERSION.INCREMENTAL).append(")");
                            emailBuilder.append("\nOS API Level: ").append(Build.VERSION.SDK_INT);
                            emailBuilder.append("\nDevice: ").append(Build.DEVICE);
                            emailBuilder.append("\nManufacturer: ").append(Build.MANUFACTURER);
                            emailBuilder.append("\nModel (and Product): ").append(Build.MODEL).append(" (")
                                    .append(Build.PRODUCT).append(")");
                            PackageInfo appInfo = null;
                            try {
                                appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                            } catch (PackageManager.NameNotFoundException e) {
                                e.printStackTrace();
                            }
                            assert appInfo != null;
                            emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName);
                            emailBuilder.append("\nApp Version Code: ").append(appInfo.versionCode);

                            intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
                            startActivity(Intent.createChooser(intent, "Send via"));
                            break;
                        case 4:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Share").build());
                            Intent i = new AppInviteInvitation.IntentBuilder(
                                    getString(R.string.invitation_title))
                                            .setMessage(getString(R.string.invitation_message))
                                            .setCallToActionText(getString(R.string.invitation_cta)).build();
                            startActivityForResult(i, REQUEST_INVITE);
                            break;
                        case 5:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Other Apps").build());
                            String PlayStoreDevAccount = "https://play.google.com/store/apps/developer?id=P.I.M.P.";
                            Intent devPlay = new Intent(Intent.ACTION_VIEW, Uri.parse(PlayStoreDevAccount));
                            startActivity(devPlay);
                            break;
                        case 6:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Report Bugs").build());
                            startActivity(new Intent(MainActivity.this, GittyActivity.class));
                            break;
                        case 7:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Donate").build());

                            String base64EncodedPublicKey = getString(R.string.base64);
                            mHelper = new IabHelper(getApplicationContext(), base64EncodedPublicKey);
                            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                                public void onIabSetupFinished(IabResult result) {
                                    if (!result.isSuccess()) {
                                        Toast.makeText(MainActivity.this,
                                                "Problem setting up In-app Billing: " + result,
                                                Toast.LENGTH_LONG).show();
                                    }
                                }
                            });

                            final Dialog dialog = new Dialog(MainActivity.this);
                            dialog.setContentView(R.layout.dialog_donate);
                            dialog.setTitle("Donate");

                            String[] title = { "Coke", "Coffee", "Burger", "Pizza", "Meal" };
                            String[] price = { "Rs. 10.00", "Rs. 50.00", "Rs. 100.00", "Rs. 500.00",
                                    "Rs. 1,000.00" };

                            ListView listView = (ListView) dialog.findViewById(R.id.list);
                            listView.setAdapter(new DonateListAdapter(MainActivity.this, title, price));
                            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> parent, View view, int position,
                                        long id) {
                                    switch (position) {
                                    case 0:
                                        mHelper.launchPurchaseFlow(MainActivity.this, SKU_COKE, 1,
                                                mPurchaseFinishedListener, "payload");
                                        break;
                                    case 1:
                                        mHelper.launchPurchaseFlow(MainActivity.this, SKU_COFFEE, 1,
                                                mPurchaseFinishedListener, "payload");
                                        break;
                                    case 2:
                                        mHelper.launchPurchaseFlow(MainActivity.this, SKU_BURGER, 1,
                                                mPurchaseFinishedListener, "payload");
                                        break;
                                    case 3:
                                        mHelper.launchPurchaseFlow(MainActivity.this, SKU_PIZZA, 1,
                                                mPurchaseFinishedListener, "payload");
                                        break;
                                    case 4:
                                        mHelper.launchPurchaseFlow(MainActivity.this, SKU_MEAL, 1,
                                                mPurchaseFinishedListener, "payload");
                                        break;
                                    }
                                }
                            });

                            dialog.show();
                            break;
                        case 8:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("About").build());
                            new LibsBuilder().withLicenseShown(true).withVersionShown(true)
                                    .withActivityStyle(Libs.ActivityStyle.DARK).withAboutVersionShown(true)
                                    .withActivityTitle(getString(R.string.app_name)).withAboutIconShown(true)
                                    .withListener(libsListener).start(MainActivity.this);
                            break;
                        case 9:
                            mTracker.send(new HitBuilders.EventBuilder().setCategory("Action")
                                    .setAction("Translate").build());
                            Intent translate = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://poeditor.com/join/project/AZQxDV2440"));
                            startActivity(translate);
                            break;
                        default:
                            break;
                        }
                    } else {
                        flag = false;
                    }
                    return flag;
                }
            }).withSavedInstance(savedInstanceState).build();

    AppUpdater appUpdater = new AppUpdater(this);
    appUpdater.start();

    final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
            .allowNewDirectoryNameModification(true).newDirectoryName("CfBCamera")
            .initialDirectory(
                    sharedPreferences.getString("pic_location", "/storage/emulated/0/CompanionForBand/Camera"))
            .build();
    mDialog = DirectoryChooserFragment.newInstance(config);

    new BandUtils().execute();

    CustomActivityOnCrash.install(this);
}

From source file:com.tjcj.carrental.fragment.DriverFragment.java

/**
 * string?bitmap/*from w w w .j  a v  a 2 s . c om*/
 *
 * @param st
 */
public static Bitmap convertStringToIcon(String st) {
    Bitmap bitmap = null;
    try {
        byte[] bitmapArray;
        bitmapArray = Base64.decode(st, Base64.DEFAULT);
        bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        return bitmap;
    } catch (Exception e) {
        return null;
    }
}

From source file:jp.app_mart.billing.AppmartHelper.java

/**
 * ?/*from   ww w  .  ja  v  a2 s.c om*/
 * @param serviceId
 * @param developId
 * @param strLicenseKey
 * @param strPublicKey
 * @return
 */
public static String createEncryptedData(String serviceId, String developId, String strLicenseKey,
        String strPublicKey) {
    final String SEP_SYMBOL = "&";
    StringBuilder infoDataSB = new StringBuilder();
    infoDataSB.append(serviceId).append(SEP_SYMBOL);
    // ?ID 
    infoDataSB.append(developId).append(SEP_SYMBOL);
    // 
    infoDataSB.append(strLicenseKey);
    String strEncryInfoData = "";
    try {
        KeyFactory keyFac = KeyFactory.getInstance("RSA");
        KeySpec keySpec = new X509EncodedKeySpec(Base64.decode(strPublicKey.getBytes(), Base64.DEFAULT));
        Key publicKey = keyFac.generatePublic(keySpec);
        if (publicKey != null) {
            Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            byte[] EncryInfoData = cipher.doFinal(infoDataSB.toString().getBytes());
            strEncryInfoData = new String(Base64.encode(EncryInfoData, Base64.DEFAULT));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        strEncryInfoData = "";
        Log.e("AppmartHelper", "?");
    }
    return strEncryInfoData.replaceAll("(\\r|\\n)", "");
}

From source file:com.charabia.SmsViewActivity.java

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);

    switch (reqCode) {
    case SMS_KEY_CONTACT:
        if (resultCode == RESULT_OK) {
            Uri uri = data.getData();/* ww  w .  j a v  a  2 s  . c om*/

            ContentResolver cr = getContentResolver();

            Cursor cursor = cr.query(uri, new String[] { Contacts.LOOKUP_KEY }, null, null, null);

            String lookup = null;

            if (cursor.moveToFirst()) {
                lookup = cursor.getString(0);
            }

            cursor.close();

            if (lookup == null) {
                Toast.makeText(this, R.string.unexpected_error, Toast.LENGTH_LONG).show();
                return;
            }

            cursor = cr.query(Data.CONTENT_URI, new String[] { Phone.NUMBER },
                    Data.MIMETYPE + "=? AND " + Data.LOOKUP_KEY + "=?",
                    new String[] { Phone.CONTENT_ITEM_TYPE, lookup }, null);

            ArrayList<String> options = new ArrayList<String>();

            while (cursor.moveToNext()) {
                options.add(cursor.getString(0));
            }

            cursor.close();

            final String[] phoneList = options.toArray(new String[0]);

            Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.send_invit_on_phone);
            builder.setItems(phoneList, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {

                    keypair = tools.loadKeyPair();
                    RSAPublicKey pubKey = (RSAPublicKey) keypair.getPublic();

                    byte[] encoded = pubKey.getModulus().toByteArray();

                    byte[] data = new byte[3 + encoded.length];

                    data[0] = Tools.MAGIC[0];
                    data[1] = Tools.MAGIC[1];
                    data[2] = Tools.PUBLIC_KEY_TYPE;

                    System.arraycopy(encoded, 0, data, 3, encoded.length);

                    tools.sendData(phoneList[i], Tools.INVITATION, "", data);

                }
            });

            builder.create().show();
        } else {
            Toast.makeText(this, R.string.error_create_key, Toast.LENGTH_LONG).show();
        }
        break;
    case IntentIntegrator.REQUEST_CODE:
        if (resultCode == RESULT_OK) {
            try {
                String contents = data.getStringExtra("SCAN_RESULT");
                @SuppressWarnings("unused")
                String format = data.getStringExtra("SCAN_RESULT_FORMAT");
                // Handle successful scan

                // TODO: add more tests control

                String[] infos = contents.split("\n");

                Cipher rsaCipher = Cipher.getInstance(Tools.RSA_CIPHER_ALGO);

                if (mode == MODE_ESCLAVE) {
                    // Save key and show crypted key on QRCode
                    key = tools.generateKeyAES().getEncoded();

                    KeyFactory keyFact = KeyFactory.getInstance("RSA");

                    PublicKey pubkey = keyFact.generatePublic(
                            new RSAPublicKeySpec(new BigInteger(infos[1]), new BigInteger(infos[2])));

                    rsaCipher.init(Cipher.ENCRYPT_MODE, pubkey);

                    int blockSize = rsaCipher.getBlockSize();

                    int nbBlock = key.length / blockSize;
                    int reste = key.length % blockSize;

                    byte[] cryptedKey = new byte[(nbBlock + 1) * rsaCipher.getOutputSize(blockSize)];

                    int offset = 0;

                    for (int i = 0; i < nbBlock; i++) {
                        offset += rsaCipher.doFinal(key, i * blockSize, blockSize, cryptedKey, offset);
                    }

                    rsaCipher.doFinal(key, nbBlock * blockSize, reste, cryptedKey, offset);

                    IntentIntegrator.shareText(SmsViewActivity.this,
                            prefPhoneNumber + "\n" + Base64.encodeToString(cryptedKey, Base64.NO_WRAP));

                } else {

                    // We have read crypted key, so decode it
                    rsaCipher.init(Cipher.DECRYPT_MODE, keypair.getPrivate());

                    byte[] cryptedData = Base64.decode(infos[1], Base64.NO_WRAP);

                    int blockSize = rsaCipher.getBlockSize();
                    int nbBlock = cryptedData.length / blockSize;

                    int offset = 0;

                    byte[] tempKey = new byte[(nbBlock + 1) * blockSize];

                    for (int i = 0; i < nbBlock; i++) {
                        offset += rsaCipher.doFinal(cryptedData, i * blockSize, blockSize, tempKey, offset);
                    }

                    key = new byte[offset];
                    System.arraycopy(tempKey, 0, key, 0, offset);
                }

                phoneNumber = infos[0];

                // store the key
                // TODO dialog to confirm add contact in mode SLAVE
                try {
                    new Tools(this).updateOrCreateContactKey(phoneNumber, key);
                } catch (NoContactException e) {
                    e.printStackTrace();
                    // propose to add contact
                    Intent newIntent = new Intent(Intents.SHOW_OR_CREATE_CONTACT);
                    newIntent.setData(Uri.fromParts("tel", phoneNumber, null));
                    startActivityForResult(newIntent, ADD_CONTACT);
                    return;
                }

                Toast.makeText(this, getString(R.string.contact_added) + "\n" + phoneNumber, Toast.LENGTH_LONG)
                        .show();

            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(this, R.string.error_create_key, Toast.LENGTH_LONG).show();
            }

        } else {
            // TODO: string
            Toast.makeText(this, R.string.fail_reading_tag, Toast.LENGTH_LONG).show();
        }
        break;
    case ADD_CONTACT:
        try {
            tools.updateOrCreateContactKey(phoneNumber, key);
            Toast.makeText(this, getString(R.string.contact_added) + "\n" + phoneNumber, Toast.LENGTH_LONG)
                    .show();
        } catch (NoContactException e) {
            e.printStackTrace();
            Toast.makeText(this, R.string.error_create_key, Toast.LENGTH_LONG).show();
        }
        break;
    }

}

From source file:reportsas.com.formulapp.Formulario.java

public void CapturaF() {
    if (parametroCam == null) {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1);

    } else {//from   w  w  w. jav a 2 s  .co m

        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.dialog_imagen);
        dialog.setTitle("Captura de Formulario");
        byte[] decodedByte = Base64.decode(parametroCam.getValor(), 0);

        ImageView imageview = (ImageView) dialog.findViewById(R.id.ImaVcaptura);
        Button Button1 = (Button) dialog.findViewById(R.id.NuevaToma);
        Button Button2 = (Button) dialog.findViewById(R.id.btn_cerrar);

        imageview.setImageBitmap(BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length));
        Button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 1);
                dialog.dismiss();
            }
        });

        Button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog.dismiss();
            }
        });

        dialog.show();

    }

}

From source file:biz.bokhorst.xprivacy.Util.java

private static PublicKey getPublicKey(Context context) throws Throwable {
    // Read public key
    String sPublicKey = "";
    InputStreamReader isr = new InputStreamReader(context.getAssets().open("XPrivacy_public_key.txt"), "UTF-8");
    BufferedReader br = new BufferedReader(isr);
    String line = br.readLine();//from w w w .j  a v a 2  s  . c  o  m
    while (line != null) {
        if (!line.startsWith("-----"))
            sPublicKey += line;
        line = br.readLine();
    }
    br.close();
    isr.close();

    // Create public key
    byte[] bPublicKey = Base64.decode(sPublicKey, Base64.NO_WRAP);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    X509EncodedKeySpec encodedPubKeySpec = new X509EncodedKeySpec(bPublicKey);
    return keyFactory.generatePublic(encodedPubKeySpec);
}

From source file:com.rbsoftware.pfm.personalfinancemanager.utils.Utils.java

/**
 * Decrypts string/*from  ww w . j a  v  a  2 s.c  om*/
 *
 * @param input string
 * @return decrypted string
 */
public static String decrypt(String input) {
    return new String(Base64.decode(input, Base64.DEFAULT));
}

From source file:com.pdftron.pdf.utils.Utils.java

public static String decryptIt(Context context, String value) {
    String cryptoPass = context.getString(context.getApplicationInfo().labelRes);
    try {/*from   w w  w. j a  v  a  2s . co m*/
        DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey key = keyFactory.generateSecret(keySpec);

        byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
        // cipher is not thread safe
        Cipher cipher = Cipher.getInstance("DES");
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes));

        String decrypedValue = new String(decrypedValueBytes);
        Log.d("MiscUtils", "Decrypted: " + value + " -> " + decrypedValue);
        return decrypedValue;

    } catch (Exception e) {
        Log.e(e.getClass().getName(), e.getMessage());
    }
    return value;
}

From source file:com.savor.ads.core.Session.java

private Object StringToObject(String str) {
    Object obj = null;//from   w ww  .  jav a 2s . co  m
    byte[] base64Bytes;
    ByteArrayInputStream bais = null;
    try {
        String productBase64 = str;
        if (null == productBase64 || TextUtils.isEmpty(productBase64.trim())) {
            return null;
        }

        base64Bytes = Base64.decode(productBase64, Base64.DEFAULT);
        bais = new ByteArrayInputStream(base64Bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        obj = ois.readObject();
        ois.close();
    } catch (Exception e) {
    } finally {
        if (bais != null) {
            try {
                bais.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return obj;
}

From source file:com.microsoft.aad.adal.Oauth2.java

public static String decodeProtocolState(String encodedState) {

    if (!StringExtensions.IsNullOrBlank(encodedState)) {
        byte[] stateBytes = Base64.decode(encodedState, Base64.NO_PADDING | Base64.URL_SAFE);

        return new String(stateBytes);
    }//from  w ww . ja v a2s  . c o m

    return null;
}