使用外部Android应用程序安全地打开文件

使用外部Android应用程序安全地打开文件

本文介绍了使用外部Android应用程序安全地打开文件,而无需将文件复制到外部存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个安全的应用程序,用户可以在其中浏览某些文件,并使用手机上显示的应用程序打开它们.所以就目前而言,我的应用程序确实很安全,文件已经很好地加密了,但是我有一个重大的中断.确实,我正在使用我的应用程序打开不同类型(pdf,doc,txt,jpg,...)的用户安全文件,因此我正在使用用户电话上的外部应用程序打开它们.但是我的问题在这里,因为要让另一个应用程序打开这些文件,我需要为要使用的应用程序提供一个Android存储位置.

I'm doing a secure application, where an user can browse some file and open them with application presents on the phone. So for now, my application is really secure, files are well encrypted, but I have one MAJOR break. Indeed, I'm using my application to open the user secure files which are of different types (pdf, doc, txt, jpg, ...) so I'm using the external application presents on the user phone to open them. But my issue is here, because to let another application to open these files, I need to provide an Android storage location to the application that I want to use.

这是我现在正在使用的代码:

Here is the code that I'm using right now:

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File fileToOpen = new File(activity.getExternalCacheDir().getAbsolutePath() +
    "/" + fileName);

MimeTypeMap mime = MimeTypeMap.getSingleton();
String extension = fileToOpen.getName().substring(
        fileToOpen.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(extension);
intent.setAction(Intent.ACTION_VIEW);

intent.setDataAndType(Uri.fromFile(fileToOpen), type);

Manager.getActivity().startActivityForResult(intent,
        ExplorerActivity.FILE_CLOSED_SUCCESSFULLY);

因此,正如您在我的代码中看到的那样,我需要将我的真实文件存储到缓存目录中以将其打开,因此,如果小偷可以访问用户电话,它可以打开存在于此目录中的真实文件,因此我的应用程序不再安全.当然,在用户关闭该文件并将其加密后,我会立即删除该纯文件,但是删除并不意味着该文件已从手机中完全删除.在删除之前,我用一些空字节重写,但这不足以确保此文件的安全存储.

So, as you can see in my code, I need to store my real file into the cache directory to open it, so if a thief has an access to the user phone, it can open real files presents into this directory so my application is not secure anymore.Of course I'm deleting this plain file right after the user has closed it and I have encrypted it, but the deletion doesn't mean that the file is totally deleted from the phone. Before deletion, I'm rewriting with some null byte but it's not enough for a secure deltion of this file.

因此,现在,我想从您这里获得实现我想要做的一个主意:打开一个文件而不将其存储到Android硬盘中.

So now, what I want from you it's an idea to achieve what I want to do: open a file without storing it into the Android hard storage.

以下是我的一些线索:

  • 使用我自己的应用程序打开文件(但是要实现很多,因为文件类型太多,我真的不喜欢开发已经存在的文件)
  • 找到一种无需在应用程序外部存储文件即可打开文件的解决方案(我的意思是直接使用该文件的字节数组打开文件)
  • 将文件存储到手机RAM中(我不知道是否可能)

因此,这不是一个详尽的列表,任何其他建议将不胜感激.并且,如果您可以提供有关我提出的一种解决方案的帮助,请不要犹豫.不要犹豫,告诉我我的想法之一是完全不可能的还是错误的.

So this is a non-exhaustive list and any other suggestion will be appreciated. And if you can provide any help about one of the solution that I have proposed, please don't hesitate. Don't hesitate also to tell me if one of my ideas are completely impossible or wrong.

推荐答案

您是否尝试过覆盖openFile的自己的contentProvider,所以您打开了应用专用的文件,并返回了filedescriptor可供其他应用访问

Have you tried your own contentProvider which overrides openFile , so files that are private to your app are opened by you and you return filedescriptor which is accessible to other apps

这篇关于使用外部Android应用程序安全地打开文件,而无需将文件复制到外部存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:44