Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6208577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:49:57+00:00 2026-05-24T05:49:57+00:00

The basic idea is that: I’m downloading encrypted image file from internet and start

  • 0

The basic idea is that: I’m downloading encrypted image file from internet and start decrypting it.

After it’s done I want to save it to the cache (if this is the best way to do what I need) and than load it in a lazy loading listview.

But for now I just want to test the showing image after decryption in an ImageView.

Here is the code I’m using :

package com.android.basetableview;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.ImageView;

public class BaseTableViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        ImageView imgView = (ImageView) findViewById(R.id.imgView);

        Bitmap myBitmap = getBitmapFromURL("http://pu-twitter.netau.net/card1.png");
        imgView.setImageBitmap(myBitmap);
    }


    public static Bitmap getBitmapFromURL(String src) {
        Bitmap myBitmap = null;
            try {

                URL url = new URL(src);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.connect();

                //Decryption
                try {
                Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
                SecretKeySpec keySpec = new SecretKeySpec("01234567890abcde".getBytes(), "AES");
                IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes());
                cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

                InputStream input = connection.getInputStream();
                CipherInputStream cis = new CipherInputStream(input, cipher);
                FileOutputStream fos  = new FileOutputStream(
                           new File(Environment.getExternalStorageDirectory(), "card2_decrypted.jpg"));
                byte[] b = new byte[8];
                int i;

                while ((i = cis.read(b)) != -1) {
                  fos.write(b, 0, i);
                }
                fos.flush(); fos.close();
                cis.close(); input.close();


                //myBitmap = BitmapFactory.decodeStream(input);

                }
                catch(Exception e){
                    e.fillInStackTrace();
                    Log.v("ERROR","Errorchence : "+e);
                }

                return myBitmap;


            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
}

As you can see, I’m saving the decrypted image in sdcard, but the images that I’m using are small and maybe the cache will be better option. So if you guys can give me some advice how can I do that and which is the best way to save the images and then show them as a content in a ImageView.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:49:57+00:00Added an answer on May 24, 2026 at 5:49 am

    OK you don’t need to save the images:

        public static Bitmap getBitmapFromURL(String src) {
            Bitmap myBitmap = null;
                try {
    
                    URL url = new URL(src);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setDoInput(true);
                    connection.connect();
    
                    //Decryption
                    try {
                    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
                    SecretKeySpec keySpec = new SecretKeySpec("01234567890abcde".getBytes(), "AES");
                    IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes());
                    cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
    
                    InputStream input = connection.getInputStream();
                    CipherInputStream cis = new CipherInputStream(input, cipher);
    
    
                    myBitmap = BitmapFactory.decodeStream(cis);
    
                    }
                    catch(Exception e){
                        e.fillInStackTrace();
                        Log.v("ERROR","Errorchence : "+e);
                    }
    
                    return myBitmap;
    
    
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From a blog: The basic idea with CSS expressions is that you will have
Here's the basic idea: There is a java window (main) that opens another java
I understand the basic idea that when an array is the sole operand of
the basic idea is that you have some class that has a reference type
References in C++ are baffling me. :) The basic idea is that I'm trying
I'm currently trying to create the app.config at runtime. The basic idea is that
I'm creating my own template engine using PHP. The basic idea is that for
The basic idea behind a Cancel button is to enable closing your window with
The basic idea of a masterpage is simple -- you have a block of
The basic idea is to take a string and evaluate it against an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.