對不起,提出這個問題,但我沒有清楚的加密和解密文件夾的想法,我想加密一堆選定的圖像,如在這篇文章 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,這樣我可以減少加密整個圖像的時間?
看到這可能是對你有幫助。 http://stackoverflow.com/questions/6266076/can-we-encrypt-a-folder-in-android –