use of com.keepassdroid.database.PwDbHeader in project KeePassDX by Kunzisoft.
the class PwManagerOutputTest method testFinalKey.
public void testFinalKey() throws PwDbOutputException {
ByteArrayOutputStream bActual = new ByteArrayOutputStream();
PwDbV3Output pActual = new PwDbV3OutputDebug(mPM, bActual, true);
PwDbHeader hActual = pActual.outputHeader(bActual);
byte[] finalKey = pActual.getFinalKey(hActual);
assertArrayEquals("Keys mismatched", mPM.finalKey, finalKey);
}
use of com.keepassdroid.database.PwDbHeader in project KeePassDX by Kunzisoft.
the class PwDbV3Output method output.
@Override
public void output() throws PwDbOutputException {
prepForOutput();
PwDbHeader header = outputHeader(mOS);
byte[] finalKey = getFinalKey(header);
Cipher cipher;
try {
if (mPM.algorithm == PwEncryptionAlgorithm.Rjindal) {
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
} else if (mPM.algorithm == PwEncryptionAlgorithm.Twofish) {
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
} else {
throw new Exception();
}
} catch (Exception e) {
throw new PwDbOutputException("Algorithm not supported.");
}
try {
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(finalKey, "AES"), new IvParameterSpec(header.encryptionIV));
CipherOutputStream cos = new CipherOutputStream(mOS, cipher);
BufferedOutputStream bos = new BufferedOutputStream(cos);
outputPlanGroupAndEntries(bos);
bos.flush();
bos.close();
} catch (InvalidKeyException e) {
throw new PwDbOutputException("Invalid key");
} catch (InvalidAlgorithmParameterException e) {
throw new PwDbOutputException("Invalid algorithm parameter.");
} catch (IOException e) {
throw new PwDbOutputException("Failed to output final encrypted part.");
}
}
use of com.keepassdroid.database.PwDbHeader in project keepass2android by PhilippC.
the class PwDbV3Output method output.
@Override
public void output() throws PwDbOutputException {
prepForOutput();
PwDbHeader header = outputHeader(mOS);
byte[] finalKey = getFinalKey(header);
Cipher cipher;
try {
if (mPM.algorithm == PwEncryptionAlgorithm.Rjindal) {
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
} else if (mPM.algorithm == PwEncryptionAlgorithm.Twofish) {
cipher = CipherFactory.getInstance("TWOFISH/CBC/PKCS7PADDING");
} else {
throw new Exception();
}
} catch (Exception e) {
throw new PwDbOutputException("Algorithm not supported.");
}
try {
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(finalKey, "AES"), new IvParameterSpec(header.encryptionIV));
CipherOutputStream cos = new CipherOutputStream(mOS, cipher);
BufferedOutputStream bos = new BufferedOutputStream(cos);
outputPlanGroupAndEntries(bos);
bos.flush();
bos.close();
} catch (InvalidKeyException e) {
throw new PwDbOutputException("Invalid key");
} catch (InvalidAlgorithmParameterException e) {
throw new PwDbOutputException("Invalid algorithm parameter.");
} catch (IOException e) {
throw new PwDbOutputException("Failed to output final encrypted part.");
}
}
Aggregations