android解密图像在飞行中

时间:2011-11-28 13:04:35

标签: android encryption on-the-fly

我正在尝试在我的应用程序中动态解密图像。我正在通过互联网下载它们而不是我想解密它们并将它们显示为背景或在imageview中。所以我的问题是我无法弄清楚如何制作整个逻辑。

现在我从他们的路径获取sdcard中的图像,这是我写的方法生成的:

    public static String getImagePathFromExternalStorage(String server, int userId, String filename){
        String path=Environment.getExternalStorageDirectory()
        + "/Documents/Users/"+server+"/"+userId+"/Storage/" + filename;

        return path;
    }

    public static String getImagePathFromInternalStorage(String server, int userId, String filename, Context context){
        String path = context.getFilesDir() + "/documents/users/"+server+"/"+userId+"/storage/"+filename;

        return path;
    }

我正在解密这样的图像:

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);
ByteArrayInputStream input = new ByteArrayInputStream(mediaCollBuffer); 
CipherInputStream cis = new CipherInputStream(input, cipher);

所以我试图找出如何通过它的路径获取文件,动态解密并将其设置为背景。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

File bufferFile = new File(path);
FileInputStream fis   = new FileInputStream(bufferFile);

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);
CipherInputStream cis = new CipherInputStream(fis, cipher);
Bitmap ops = BitmapFactory.decodeStream(cis);
logo.setImageBitmap(ops);

我认为这应该有所帮助。