private void Construct(IOConnectionInfo iocFile, bool bThrowIfDbFile) { byte[] pbFileData; pbFileData = iocFile.IsFileStream() ? ((MemoryStream)iocFile.Stream).ToArray() : IOConnection.ReadFile(iocFile); if (pbFileData == null) { throw new FileNotFoundException(); } if (bThrowIfDbFile && (pbFileData.Length >= 8)) { uint uSig1 = MemUtil.BytesToUInt32(MemUtil.Mid(pbFileData, 0, 4)); uint uSig2 = MemUtil.BytesToUInt32(MemUtil.Mid(pbFileData, 4, 4)); if (((uSig1 == KdbxFile.FileSignature1) && (uSig2 == KdbxFile.FileSignature2)) || ((uSig1 == KdbxFile.FileSignaturePreRelease1) && (uSig2 == KdbxFile.FileSignaturePreRelease2)) || ((uSig1 == KdbxFile.FileSignatureOld1) && (uSig2 == KdbxFile.FileSignatureOld2))) #if KeePassLibSD { throw new Exception(KLRes.KeyFileDbSel); } #else { throw new InvalidDataException(KLRes.KeyFileDbSel); } #endif } byte[] pbKey = LoadXmlKeyFile(pbFileData); if (pbKey == null) { pbKey = LoadKeyFile(pbFileData); } if (pbKey == null) { throw new InvalidOperationException(); } m_strPath = iocFile.Path; m_pbKeyData = new ProtectedBinary(true, pbKey); MemUtil.ZeroByteArray(pbKey); }