对不起,提出这个问题,但我没有清楚的加密和解密文件夹的想法,我想加密一堆选定的图像,如在这篇文章encrypt/decrypt中提到的,但它是服用大量的时间来加密一堆选择的图像,所以我试图加密包含一个文件夹中选中的图像,但它给我FileNotFoundException异常:打开失败(是一个目录)我已经更新了加密功能,如下图所示android:是否可以加密文件夹
static void encrypt() throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
// Here you read the cleartext.
FileInputStream fis = new FileInputStream(Environment.getExternalStorageDirectory()+"/.myapp/.private");
// This stream write the encrypted text. This stream will be wrapped by another stream.
FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory()+"/.myapp/.encyrpted");
// Length is 16 byte
SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(), "AES");
// Create cipher
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, sks);
// Wrap the output stream
CipherOutputStream cos = new CipherOutputStream(fos, cipher);
// Write bytes
int b;
byte[] d = new byte[8];
while((b = fis.read(d)) != -1) {
cos.write(d, 0, b);
}
// Flush and close streams.
cos.flush();
cos.close();
fis.close();}
所以我如何加密文件夹sdcard/.myapp/.private,这样我可以减少加密整个图像的时间?
+0
看到这可能是对你有帮助。 http://stackoverflow.com/questions/6266076/can-we-encrypt-a-folder-in-android –