diff --git a/alice/src/main/java/com/rockaport/alice/Alice.java b/alice/src/main/java/com/rockaport/alice/Alice.java index 16f3fbe..624c2e5 100644 --- a/alice/src/main/java/com/rockaport/alice/Alice.java +++ b/alice/src/main/java/com/rockaport/alice/Alice.java @@ -241,7 +241,7 @@ public synchronized void encrypt(File input, File output, char[] password) // allocate variables int bytesRead; byte[] encryptedBytes; - byte[] inputStreamBuffer = new byte[4096]; + byte[] inputStreamBuffer = new byte[1024]; // setup streams bufferedInputStream = new BufferedInputStream(new FileInputStream(input)); @@ -250,7 +250,7 @@ public synchronized void encrypt(File input, File output, char[] password) // write the initialization vector bufferedOutputStream.write(initializationVector); - while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) { + while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) { // encrypt encryptedBytes = cipher.update(inputStreamBuffer, 0, bytesRead); @@ -322,8 +322,8 @@ public synchronized void encrypt(InputStream input, OutputStream output, char[] // allocate variables int bytesRead; - byte[] inputStreamBuffer = new byte[4096]; - while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) { + byte[] inputStreamBuffer = new byte[1024]; + while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) { // encrypt bufferedOutputStream.write(cipher.update(inputStreamBuffer, 0, bytesRead)); } @@ -455,7 +455,7 @@ public synchronized void decrypt(File input, File output, char[] password) // allocate loop buffers and variables int bytesRead; int numBytesToProcess; - byte[] inputStreamBuffer = new byte[4096]; + byte[] inputStreamBuffer = new byte[1024]; long bytesLeft = input.length() - context.getIvLength(); // subtract the mac length if enabled @@ -464,7 +464,7 @@ public synchronized void decrypt(File input, File output, char[] password) } // decrypt - while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) { + while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) { numBytesToProcess = (bytesRead < bytesLeft) ? bytesRead : (int) bytesLeft; if (numBytesToProcess <= 0) { @@ -545,10 +545,10 @@ public synchronized void decrypt(InputStream input, OutputStream output, char[] // allocate loop buffers and variables int bytesRead; - byte[] inputStreamBuffer = new byte[4096]; + byte[] inputStreamBuffer = new byte[1024]; // decrypt - while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) { + while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) { bufferedOutputStream.write(cipher.update(inputStreamBuffer, 0, bytesRead)); } @@ -661,4 +661,4 @@ private void closeStream(Closeable stream) { } } } -} \ No newline at end of file +}