Android 安全图像存储
我正在开发一个适用于 Android 2.2 的应用程序,它允许用户从网络服务器购买和下载图像。一旦他下载了这些图像,只有这个应用程序应该能够查看这些图像。我能想到的一种可能的方法是将图像加密并保存在SD卡中。
但是,我担心的是,即使在加密之后,这些文件对于文件资源管理器应用程序也是可见的(可以删除/重命名/移动文件)。是否可以将这些文件以其他应用程序不可见的方式存储在 SD 卡中?
BlackBerry 中有一个前向锁定功能(http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/io/file/ExtendedFileConnection.html)。一旦文件保存到使用这种方法的SD卡,它只会对相应的应用程序和设备可见。Android有类似的东西吗?
是否建议将图像存储在sqlite数据库中。数据库文件对手机中的其他应用程序不可见。(PS:会有大量图像)
是否可以将图像文件保存为.asec文件。是否有任何 api 可以将文件转换为 .asec 格式?我知道文件资源管理器不会显示 .asec 文件。
请您指导我或建议针对这种情况的理想解决方案。
I am developing an application for Android 2.2 that lets the user purchase and download images from web server.Once he downloads these images, only this application should be able to view these images. One of the possible way I could think of was to encrypt and save the images in the SD card.
But,my concern is that, even after encryption, these files will be visible for file explorer applications(which can delete/rename/move the files). Is it possible to store these files in SD card in such a way that, it is not visible to other applications?
There is a forward locking functionality in BlackBerry(http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/io/file/ExtendedFileConnection.html).Once the file is saved onto sd card using this method, it will be visible only to the corresponding application and device.Is there something like that for android?
Will it be advisable to store the images in sqlite database.The database file is not visible to other apps in the phone.(PS: There will be large number of images)
Is it possible to save the image files as .asec files. Is there any api that convert a file to .asec format?I understand .asec files won't be shown by File explorers.
Please could you direct me or suggest an ideal solution for this scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一种解决方案可以将数据存储在 SD 卡上,从而使未 root 的手机无法在设备上的文件查看器中查看文件。
解决方案是将数据保存在应用程序数据文件夹中,并激活在清单中为应用程序自动选择位置。这使用户可以选择将应用程序保存在外部或内部的位置,并且所有图像都位于应用程序拥有的私人文件夹内。
只有一个缺点。用户可以通过应用程序管理器删除所有文件。她将被警告,这可能会破坏应用程序,但如果无法重新下载图像,如果应用程序被删除或用户认为删除应用程序数据是一件好事,用户将丢失所有购买的项目。
但是,在已 root 的手机上,可以将图像从私人文件夹中复制出来。因此您应该考虑以某种方式加密图像。然而,加密并不那么容易,因为用户总是可以尝试从源代码或网络流量中提取加密密钥。
There is a solution to store the data on the SD-Card in a way that makes it impossible to see the files in an on device file viewer on a non rooted phone.
The solution is to save the data in your apps data folder and activate the automatic location choosing for your app in the manifest. This lets the user choose where to save the app external or internal and all the images are inside the private folder that is owned by the app.
There is only one drawback. The user can delete all files through the app manager. She will be warned that this will may break the app but if there is no way to redownload images the user will loose all purchased items if the app gets deleted or the user decides it would be a good thing to delete the app data.
On a rooted phone however the images can be copied away from the private folder. Therefore you should think about encrypting the image in some way. Encrypting however is not that easy because the user can always try to extract the encryption key from your sourcecode or network traffic.
作为应用程序开发人员,您是用户设备上的访客。用户对设备的控制权比您以往任何时候都多。没有地方可以隐藏加密所需的密钥。你被迫表现得很好,也许你正在寻找“虽然默默无闻但安全”。
As an app developer you are a guest on a user's device. The user has more control over the device than you will ever have. There is no place to hide a secret key necessary for encryption. You are forced to play nice, perhaps you are looking for "(in)security though obscurity".
您可以将文件存储在数据库中,除非数据库大小有限制。
或者,您可以将图像存储在一个容器(例如我们的 SolFS 虚拟文件系统)中,然后从该容器中提取它们。用户仍然可以复制容器。这里的选项之一是使用某些设备 ID(例如 IMEI 代码)作为加密密钥的一部分来加密容器。
如果手机被root,用户几乎可以做任何事情,因此正如鲁克指出的那样,默默无闻成为了这个方程式的重要组成部分。
另一种选择是为图像创建自定义文件格式,以便只有您的应用程序才能加载图像数据。同样,您可以使用设备 ID 加密此类文件,以将图像“绑定”到设备。
请注意,如今知识产权(包括图像)已授权给用户,而不是设备。或者至少用户有权在其多个系统(例如不超过 3 个设备)之间移动 IP。您也可以通过使用随机密钥加密图像,然后使用每个设备的 IMEI+salt 加密随机密钥来处理此问题(因此您将随机密钥加密 3 次)。然后用户可以在他的系统之间移动文件。当然,这并不是让用户在其设备之间移动文件的唯一方法。
You can store files in the database unless there are limits on the DB size.
Or you can store images in one container (eg. our SolFS virtual file system) and extract them from that container. The user will still be able to copy container away. One of options here is to encrypt the container using some device ID (IMEI code for example) as part of the encryption key.
If the phone is rooted, the user can do virtually anything so as Rook pointed, obscurity becomes an important part of the equation.
And yet another option is to create custom file format for your images, so that only your application is able to load the image data. Again, you can encrypt such files using device's ID to "bind" the image to the device.
Note, that nowadays intellectual property (including images) is licensed to the user, not to device. Or at least the user has rights to move the IP between several of his systems (say no more than 3 devices). You can handle this as well by encrypting the image with random key, then encrypting the random key using IMEI+salt for each device (so you will have the random key encrypted say 3 times). Then the user can move the file between his systems. Of course, this is not the only way to let the user move files between his devices.
您可以将图片打包到一个文件中,该文件已加密且对其他程序无用,然后在您的应用程序中解密图像文件并显示它。其他技术是在存储在 SD 上时插入水印,然后在程序中显示时删除水印。
You could wrap the pictures into a file where its encrypted and useless to other programs then in your app you de-crypt the image file and display it. Other technique would to insert a watermark when stored on SD then remove water mark when displaying in program.
您可以对图像文件进行加密,然后将其保存在 SDCard 中。这不会阻止用户查找/复制/删除文件。您可以使用
File
类并使用File.setReadOnly()
但我认为它需要 root 访问权限。在任何情况下,用户都将拥有与您的应用程序相同的权限。最安全的方法是创建一个完整的在线查看器。
You could encrypt the image files and then save them in SDCard. This does not prevent the user to locate/copy/delete the file. You could use the
File
class and useFile.setReadOnly()
but I think it requires root access. In any case the user will have the same permissions as your app.The most secure way is to create a full online viewer.