use of com.keepassdroid.stream.HmacBlockOutputStream in project KeePassDX by Kunzisoft.
the class PwDbV4Output method output.
@Override
public void output() throws PwDbOutputException {
try {
try {
engine = CipherFactory.getInstance(mPM.dataCipher);
} catch (NoSuchAlgorithmException e) {
throw new PwDbOutputException("No such cipher", e);
}
header = (PwDbHeaderV4) outputHeader(mOS);
OutputStream osPlain;
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
CipherOutputStream cos = attachStreamEncryptor(header, mOS);
cos.write(header.streamStartBytes);
HashedBlockOutputStream hashed = new HashedBlockOutputStream(cos);
osPlain = hashed;
} else {
mOS.write(hashOfHeader);
mOS.write(headerHmac);
HmacBlockOutputStream hbos = new HmacBlockOutputStream(mOS, mPM.hmacKey);
osPlain = attachStreamEncryptor(header, hbos);
}
OutputStream osXml;
try {
if (mPM.compressionAlgorithm == PwCompressionAlgorithm.Gzip) {
osXml = new GZIPOutputStream(osPlain);
} else {
osXml = osPlain;
}
if (header.version >= PwDbHeaderV4.FILE_VERSION_32_4) {
PwDbInnerHeaderOutputV4 ihOut = new PwDbInnerHeaderOutputV4((PwDatabaseV4) mPM, header, osXml);
ihOut.output();
}
outputDatabase(osXml);
osXml.close();
} catch (IllegalArgumentException e) {
throw new PwDbOutputException(e);
} catch (IllegalStateException e) {
throw new PwDbOutputException(e);
}
} catch (IOException e) {
throw new PwDbOutputException(e);
}
}
Aggregations