createOutputStream(): allow to disable decryption
This commit is contained in:
parent
23cfd788b1
commit
80c0e7d575
2 changed files with 8 additions and 15 deletions
|
@ -64,11 +64,11 @@ public class AbstractConnectionManager {
|
|||
return createOutputStream(file, gcm, false);
|
||||
}
|
||||
|
||||
private static OutputStream createOutputStream(DownloadableFile file, boolean gcm, boolean append) {
|
||||
public static OutputStream createOutputStream(DownloadableFile file, boolean append, boolean decrypt) {
|
||||
FileOutputStream os;
|
||||
try {
|
||||
os = new FileOutputStream(file, append);
|
||||
if (file.getKey() == null) {
|
||||
if (file.getKey() == null || !decrypt) {
|
||||
return os;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -76,18 +76,11 @@ public class AbstractConnectionManager {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
if (gcm) {
|
||||
final Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER);
|
||||
SecretKeySpec keySpec = new SecretKeySpec(file.getKey(), KEYTYPE);
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(file.getIv());
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
return new CipherOutputStream(os, cipher);
|
||||
} else {
|
||||
IvParameterSpec ips = new IvParameterSpec(file.getIv());
|
||||
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(file.getKey(), KEYTYPE), ips);
|
||||
return new CipherOutputStream(os, cipher);
|
||||
}
|
||||
final Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER);
|
||||
SecretKeySpec keySpec = new SecretKeySpec(file.getKey(), KEYTYPE);
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(file.getIv());
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
return new CipherOutputStream(os, cipher);
|
||||
} catch (Exception e) {
|
||||
Log.d(Config.LOGTAG, "unable to create cipher output stream", e);
|
||||
return null;
|
||||
|
|
|
@ -215,7 +215,7 @@ public class JingleConnection implements Transferable {
|
|||
}
|
||||
this.file.getParentFile().mkdirs();
|
||||
this.file.createNewFile();
|
||||
this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file);
|
||||
this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file, false, true);
|
||||
return this.mFileOutputStream;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue