很抱歉提出这个问题,但我没有清楚加密和解密文件夹的想法,我正在尝试加密一堆选定的图像,如本文 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以便我可以减少加密整堆图像的时间?