android:是否可以加密文件夹

时间:2012-11-12 11:57:34

标签: android file encryption aes android-gallery

很抱歉提出这个问题,但我没有清楚加密和解密文件夹的想法,我正在尝试加密一堆选定的图像,如本文 encrypt/decrypt所述,但它需要花费大量时间加密一堆选定的图像,所以我试图加密包含所选图像的文件夹,但它给我filenotfoundexception:open failed(是一个目录)我更新了加密函数,如下所示

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以便我可以减少加密整堆图像的时间?

1 个答案:

答案 0 :(得分:0)

我认为您要加密文件夹以及子包含数据。

看到这可能对你有所帮助。

Can we Encrypt a folder in android?