Search in sources :

Example 1 with HmacBlockOutputStream

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);
    }
}
Also used : CipherOutputStream(javax.crypto.CipherOutputStream) PwDbOutputException(com.keepassdroid.database.exception.PwDbOutputException) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CipherOutputStream(javax.crypto.CipherOutputStream) LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) HmacBlockOutputStream(com.keepassdroid.stream.HmacBlockOutputStream) HashedBlockOutputStream(com.keepassdroid.stream.HashedBlockOutputStream) OutputStream(java.io.OutputStream) HmacBlockOutputStream(com.keepassdroid.stream.HmacBlockOutputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) HashedBlockOutputStream(com.keepassdroid.stream.HashedBlockOutputStream)

Aggregations

PwDbOutputException (com.keepassdroid.database.exception.PwDbOutputException)1 HashedBlockOutputStream (com.keepassdroid.stream.HashedBlockOutputStream)1 HmacBlockOutputStream (com.keepassdroid.stream.HmacBlockOutputStream)1 LEDataOutputStream (com.keepassdroid.stream.LEDataOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 CipherOutputStream (javax.crypto.CipherOutputStream)1