use of org.bouncycastle.crypto.io.CipherOutputStream in project Zom-Android by zom.
the class Downloader method setupOutputStream.
public static OutputStream setupOutputStream(OutputStream os, String reference) {
if (reference != null && reference.length() == 96) {
byte[] keyAndIv = hexToBytes(reference);
byte[] key = new byte[32];
byte[] iv = new byte[16];
System.arraycopy(keyAndIv, 0, iv, 0, 16);
System.arraycopy(keyAndIv, 16, key, 0, 32);
AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
cipher.init(false, new AEADParameters(new KeyParameter(key), 128, iv));
return new CipherOutputStream(os, cipher);
} else {
return os;
}
}
use of org.bouncycastle.crypto.io.CipherOutputStream in project Conversations by siacs.
the class AbstractConnectionManager method createOutputStream.
public static OutputStream createOutputStream(DownloadableFile file, boolean append, boolean decrypt) {
FileOutputStream os;
try {
os = new FileOutputStream(file, append);
if (file.getKey() == null || !decrypt) {
return os;
}
} catch (FileNotFoundException e) {
Log.d(Config.LOGTAG, "unable to create output stream", e);
return null;
}
try {
AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
cipher.init(false, new AEADParameters(new KeyParameter(file.getKey()), 128, file.getIv()));
return new CipherOutputStream(os, cipher);
} catch (Exception e) {
Log.d(Config.LOGTAG, "unable to create cipher output stream", e);
return null;
}
}
Aggregations