1

很抱歉问这个问题,但我不清楚加密和解密文件夹,我正在尝试加密一堆选定的图像,如本文 加密/解密中提到的,但加密一堆选定的图像需要很多时间,所以我尝试加密包含所选图像的文件夹,但它给了我 filenotfoundexception:open failed(is a directory) 我已经更新了加密功能,如下所示

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

4

1 回答 1

0

I think you want to encrypt folder as well as sub contain data.

See this may be its helpful to you.

Can we Encrypt a folder in android?

于 2012-11-12T12:01:07.437 回答