mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 19:47:58 +01:00
JET WORKSgit add .!
This commit is contained in:
parent
d2f979ed15
commit
422660e9fe
3 changed files with 16 additions and 20 deletions
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue