use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.
the class KdfParameters method serialize.
public static byte[] serialize(KdfParameters kdf) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
LEDataOutputStream los = new LEDataOutputStream(bos);
KdfParameters.serialize(kdf, los);
return bos.toByteArray();
}
use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.
the class PwDbHeaderOutputV4 method output.
public void output() throws IOException {
los.writeUInt(PwDbHeader.PWM_DBSIG_1);
los.writeUInt(PwDbHeaderV4.DBSIG_2);
los.writeUInt(header.version);
writeHeaderField(PwDbHeaderV4Fields.CipherID, Types.UUIDtoBytes(db.dataCipher));
writeHeaderField(PwDbHeaderV4Fields.CompressionFlags, LEDataOutputStream.writeIntBuf(db.compressionAlgorithm.id));
writeHeaderField(PwDbHeaderV4Fields.MasterSeed, header.masterSeed);
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
writeHeaderField(PwDbHeaderV4Fields.TransformSeed, header.getTransformSeed());
writeHeaderField(PwDbHeaderV4Fields.TransformRounds, LEDataOutputStream.writeLongBuf(db.numKeyEncRounds));
} else {
writeHeaderField(PwDbHeaderV4Fields.KdfParameters, KdfParameters.serialize(db.kdfParameters));
}
if (header.encryptionIV.length > 0) {
writeHeaderField(PwDbHeaderV4Fields.EncryptionIV, header.encryptionIV);
}
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
writeHeaderField(PwDbHeaderV4Fields.InnerRandomstreamKey, header.innerRandomStreamKey);
writeHeaderField(PwDbHeaderV4Fields.StreamStartBytes, header.streamStartBytes);
writeHeaderField(PwDbHeaderV4Fields.InnerRandomStreamID, LEDataOutputStream.writeIntBuf(header.innerRandomStream.id));
}
if (db.publicCustomData.size() > 0) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
LEDataOutputStream los = new LEDataOutputStream(bos);
VariantDictionary.serialize(db.publicCustomData, los);
writeHeaderField(PwDbHeaderV4Fields.PublicCustomData, bos.toByteArray());
}
writeHeaderField(PwDbHeaderV4Fields.EndOfHeader, EndHeaderValue);
los.flush();
hashOfHeader = dos.getMessageDigest().digest();
headerHmac = mos.getMac();
}
use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.
the class PwDbV3Output method outputPlanGroupAndEntries.
public void outputPlanGroupAndEntries(OutputStream os) throws PwDbOutputException {
LEDataOutputStream los = new LEDataOutputStream(os);
if (useHeaderHash() && headerHashBlock != null) {
try {
los.writeUShort(0x0000);
los.writeInt(headerHashBlock.length);
los.write(headerHashBlock);
} catch (IOException e) {
throw new PwDbOutputException("Failed to output header hash: " + e.getMessage());
}
}
// Groups
List<PwGroup> groups = mPM.getGroups();
for (int i = 0; i < groups.size(); i++) {
PwGroupV3 pg = (PwGroupV3) groups.get(i);
PwGroupOutputV3 pgo = new PwGroupOutputV3(pg, os);
try {
pgo.output();
} catch (IOException e) {
throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
}
}
// Entries
for (int i = 0; i < mPM.entries.size(); i++) {
PwEntryV3 pe = (PwEntryV3) mPM.entries.get(i);
PwEntryOutputV3 peo = new PwEntryOutputV3(pe, os);
try {
peo.output();
} catch (IOException e) {
throw new PwDbOutputException("Failed to output an entry.");
}
}
}
use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.
the class PwDbV3Output method writeExtData.
private void writeExtData(byte[] headerDigest, OutputStream os) throws IOException {
LEDataOutputStream los = new LEDataOutputStream(os);
writeExtDataField(los, 0x0001, headerDigest, headerDigest.length);
byte[] headerRandom = new byte[32];
SecureRandom rand = new SecureRandom();
rand.nextBytes(headerRandom);
writeExtDataField(los, 0x0002, headerRandom, headerRandom.length);
writeExtDataField(los, 0xFFFF, null, 0);
}
use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.
the class TypesTest method testULongMax.
public void testULongMax() throws Exception {
byte[] ulongBytes = new byte[8];
for (int i = 0; i < ulongBytes.length; i++) {
ulongBytes[i] = -1;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
LEDataOutputStream leos = new LEDataOutputStream(bos);
leos.writeLong(Types.ULONG_MAX_VALUE);
leos.close();
byte[] uLongMax = bos.toByteArray();
assertArrayEquals(ulongBytes, uLongMax);
}
Aggregations