Search in sources :

Example 6 with NullOutputStream

use of com.keepassdroid.stream.NullOutputStream in project KeePassDX by Kunzisoft.

the class PwDatabase method makeFinalKey.

public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, int numRounds) throws IOException {
    // Write checksum Checksum
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new IOException("SHA-256 not implemented here.");
    }
    NullOutputStream nos = new NullOutputStream();
    DigestOutputStream dos = new DigestOutputStream(nos, md);
    byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
    dos.write(masterSeed);
    dos.write(transformedMasterKey);
    finalKey = md.digest();
}
Also used : DigestOutputStream(java.security.DigestOutputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) NullOutputStream(com.keepassdroid.stream.NullOutputStream)

Example 7 with NullOutputStream

use of com.keepassdroid.stream.NullOutputStream in project keepass2android by PhilippC.

the class PwDatabaseV3 method makeFinalKey.

public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, int numRounds) throws IOException {
    // Write checksum Checksum
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new IOException("SHA-256 not implemented here.");
    }
    NullOutputStream nos = new NullOutputStream();
    DigestOutputStream dos = new DigestOutputStream(nos, md);
    byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
    dos.write(masterSeed);
    dos.write(transformedMasterKey);
    finalKey = md.digest();
}
Also used : DigestOutputStream(java.security.DigestOutputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) NullOutputStream(com.keepassdroid.stream.NullOutputStream)

Example 8 with NullOutputStream

use of com.keepassdroid.stream.NullOutputStream in project keepass2android by PhilippC.

the class PwDbV3Output method outputHeader.

public PwDbHeader outputHeader(OutputStream os) throws PwDbOutputException {
    // Build header
    PwDbHeaderV3 header = new PwDbHeaderV3();
    header.signature1 = PwDbHeader.PWM_DBSIG_1;
    header.signature2 = PwDbHeaderV3.DBSIG_2;
    header.flags = PwDbHeaderV3.FLAG_SHA2;
    if (mPM.getEncAlgorithm() == PwEncryptionAlgorithm.Rjindal) {
        header.flags |= PwDbHeaderV3.FLAG_RIJNDAEL;
    } else if (mPM.getEncAlgorithm() == PwEncryptionAlgorithm.Twofish) {
        header.flags |= PwDbHeaderV3.FLAG_TWOFISH;
    } else {
        throw new PwDbOutputException("Unsupported algorithm.");
    }
    header.version = PwDbHeaderV3.DBVER_DW;
    header.numGroups = mPM.getGroups().size();
    header.numEntries = mPM.entries.size();
    header.numKeyEncRounds = mPM.getNumKeyEncRecords();
    setIVs(header);
    // Write checksum Checksum
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new PwDbOutputException("SHA-256 not implemented here.");
    }
    NullOutputStream nos;
    nos = new NullOutputStream();
    DigestOutputStream dos = new DigestOutputStream(nos, md);
    BufferedOutputStream bos = new BufferedOutputStream(dos);
    try {
        outputPlanGroupAndEntries(bos);
        bos.flush();
        bos.close();
    } catch (IOException e) {
        throw new PwDbOutputException("Failed to generate checksum.");
    }
    header.contentsHash = md.digest();
    // Output header
    PwDbHeaderOutputV3 pho = new PwDbHeaderOutputV3(header, os);
    try {
        pho.output();
    } catch (IOException e) {
        throw new PwDbOutputException("Failed to output the header.");
    }
    return header;
}
Also used : PwDbOutputException(com.keepassdroid.database.exception.PwDbOutputException) DigestOutputStream(java.security.DigestOutputStream) PwDbHeaderV3(com.keepassdroid.database.PwDbHeaderV3) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) BufferedOutputStream(java.io.BufferedOutputStream) NullOutputStream(com.keepassdroid.stream.NullOutputStream)

Aggregations

NullOutputStream (com.keepassdroid.stream.NullOutputStream)8 DigestOutputStream (java.security.DigestOutputStream)8 MessageDigest (java.security.MessageDigest)8 IOException (java.io.IOException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 PwDbHeaderV3 (com.keepassdroid.database.PwDbHeaderV3)4 PwDatabaseV3 (com.keepassdroid.database.PwDatabaseV3)2 PwEntryV3 (com.keepassdroid.database.PwEntryV3)2 PwGroupV3 (com.keepassdroid.database.PwGroupV3)2 InvalidAlgorithmException (com.keepassdroid.database.exception.InvalidAlgorithmException)2 InvalidDBSignatureException (com.keepassdroid.database.exception.InvalidDBSignatureException)2 InvalidDBVersionException (com.keepassdroid.database.exception.InvalidDBVersionException)2 InvalidPasswordException (com.keepassdroid.database.exception.InvalidPasswordException)2 PwDbOutputException (com.keepassdroid.database.exception.PwDbOutputException)2 BufferedOutputStream (java.io.BufferedOutputStream)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidKeyException (java.security.InvalidKeyException)2 BadPaddingException (javax.crypto.BadPaddingException)2 Cipher (javax.crypto.Cipher)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2