public StreamEncryptionInfo(RecordInputStream rs, List <Record> outputRecs) { Record rec; rs.NextRecord(); int recSize = 4 + rs.Remaining; rec = RecordFactory.CreateSingleRecord(rs); outputRecs.Add(rec); FilePassRecord fpr = null; if (rec is BOFRecord) { _hasBOFRecord = true; if (rs.HasNextRecord) { rs.NextRecord(); rec = RecordFactory.CreateSingleRecord(rs); recSize += rec.RecordSize; outputRecs.Add(rec); if (rec is FilePassRecord) { fpr = (FilePassRecord)rec; outputRecs.RemoveAt(outputRecs.Count - 1); // TODO - add fpr not Added to outPutRecs rec = outputRecs[0]; } else { // workbook not encrypted (typical case) if (rec is EOFRecord) { // A workbook stream is never empty, so crash instead // of trying to keep track of nesting level throw new InvalidOperationException("Nothing between BOF and EOF"); } } } } else { // Invalid in a normal workbook stream. // However, some test cases work on sub-sections of // the workbook stream that do not begin with BOF _hasBOFRecord = false; } _InitialRecordsSize = recSize; _filePassRec = fpr; _lastRecord = rec; }
public RecordInputStream CreateDecryptingStream(Stream original) { FilePassRecord fpr = _filePassRec; String userPassword = Biff8EncryptionKey.CurrentUserPassword; Biff8EncryptionKey key; if (userPassword == null) { key = Biff8EncryptionKey.Create(fpr.DocId); } else { key = Biff8EncryptionKey.Create(userPassword, fpr.DocId); } if (!key.Validate(fpr.SaltData, fpr.SaltHash)) { throw new EncryptedDocumentException( (userPassword == null ? "Default" : "Supplied") + " password is invalid for docId/saltData/saltHash"); } return(new RecordInputStream(original, key, _InitialRecordsSize)); }
public StreamEncryptionInfo(RecordInputStream rs, List<Record> outputRecs) { Record rec; rs.NextRecord(); int recSize = 4 + rs.Remaining; rec = RecordFactory.CreateSingleRecord(rs); outputRecs.Add(rec); FilePassRecord fpr = null; if (rec is BOFRecord) { _hasBOFRecord = true; if (rs.HasNextRecord) { rs.NextRecord(); rec = RecordFactory.CreateSingleRecord(rs); recSize += rec.RecordSize; outputRecs.Add(rec); if (rec is FilePassRecord) { fpr = (FilePassRecord)rec; outputRecs.RemoveAt(outputRecs.Count - 1); // TODO - add fpr not Added to outPutRecs rec = outputRecs[0]; } else { // workbook not encrypted (typical case) if (rec is EOFRecord) { // A workbook stream is never empty, so crash instead // of trying to keep track of nesting level throw new InvalidOperationException("Nothing between BOF and EOF"); } } } } else { // Invalid in a normal workbook stream. // However, some test cases work on sub-sections of // the workbook stream that do not begin with BOF _hasBOFRecord = false; } _InitialRecordsSize = recSize; _filePassRec = fpr; _lastRecord = rec; }