JET WORKSgit add .!

This commit is contained in:
vanitasvitae 2017-07-31 14:21:49 +02:00
parent d2f979ed15
commit 422660e9fe
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
3 changed files with 16 additions and 20 deletions

View File

@ -25,7 +25,7 @@ import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public abstract class AesGcmNoPadding {
@ -54,10 +54,10 @@ public abstract class AesGcmNoPadding {
System.arraycopy(key, 0, keyAndIv, 0, bytes);
System.arraycopy(iv, 0, keyAndIv, bytes, bytes);
SecretKey secretKey = new SecretKeySpec(key, keyType);
IvParameterSpec ivSpec = new IvParameterSpec(iv);
cipher = Cipher.getInstance(cipherMode, "BC");
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
SecretKey keySpec = new SecretKeySpec(key, keyType);
GCMParameterSpec gcmSpec = new GCMParameterSpec(128, iv);
cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec);
}
public AesGcmNoPadding(byte[] key, byte[] iv) throws NoSuchPaddingException, NoSuchAlgorithmException,
@ -72,8 +72,8 @@ public abstract class AesGcmNoPadding {
cipher = Cipher.getInstance(cipherMode, "BC");
SecretKeySpec keySpec = new SecretKeySpec(key, keyType);
IvParameterSpec ivSpec = new IvParameterSpec(iv);
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
GCMParameterSpec gcmSpec = new GCMParameterSpec(128, iv);
cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmSpec);
}
public byte[] getKeyAndIv() {

View File

@ -72,30 +72,25 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
inputStream = bytestreamSession.getInputStream();
outputStream = new FileOutputStream(mFile);
byte[] filebuf = new byte[(int) file.getSize()];
int length = 0;
int read = 0;
byte[] bufbuf = new byte[4096];
LOGGER.log(Level.INFO, "Begin receiving bytes.");
while (read < filebuf.length) {
int r = inputStream.read(bufbuf);
if (r >= 0) {
System.arraycopy(bufbuf, 0, filebuf, read, r);
read += r;
LOGGER.log(Level.INFO, "Read " + r + " (" + read + " of " + filebuf.length + ") bytes.");
} else {
while ((length = inputStream.read(bufbuf)) >= 0) {
outputStream.write(bufbuf, 0, length);
read += length;
LOGGER.log(Level.INFO, "Read " + read + " (" + length + ") of " + file.getSize() + " bytes.");
if (read == (int) file.getSize()) {
break;
}
}
outputStream.write(filebuf);
outputStream.flush();
LOGGER.log(Level.INFO, "Reading/Writing finished.");
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Cannot get InputStream from BytestreamSession: " + e, e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
LOGGER.log(Level.INFO, "CipherInputStream closed.");
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not close InputStream: " + e, e);
}
@ -104,12 +99,12 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
if (outputStream != null) {
try {
outputStream.close();
LOGGER.log(Level.INFO, "FileOutputStream closed.");
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not close OutputStream: " + e, e);
}
}
}
notifyProgressListenersFinished();
}

View File

@ -61,6 +61,7 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer<LocalFile>
outputStream.write(fileBuf);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Exception while sending file: " + e, e);