Android 即时解密图像
我正在尝试在我的应用程序中动态解密图像。我正在通过互联网下载它们,然后我想解密它们并将它们显示为背景或在图像视图中。所以我的问题是我无法弄清楚如何构建整个逻辑。
现在我正在通过我编写的方法生成的路径从SD卡获取图像:
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);
所以我试图弄清楚如何通过文件的路径获取文件,解密它是动态的并将其设置为背景。有什么建议吗?
I'm trying to decrypt images on the fly in my application. I'm downloading them over internet and than I want to decrypt them and show 'em as backgrounds or in imageview. So my problem is that I can't figure it out how to make the whole logic.
For now I'm getting the images from sdcard by their path which is generated by a method i wrote :
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;
}
And I'm decrypting images like this :
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);
So I'm trying to figure it out how to get the file by it's path, decrypt it on the fly and set it as background. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

试试这个:
我认为这应该有帮助。
Try this :
I think this should help.