/** * Copies an Entry into a target POIFS directory, recursively */ public static void CopyNodeRecursively(Entry entry, DirectoryEntry target) { // System.err.println("copyNodeRecursively called with "+entry.GetName()+ // ","+tarGet.getName()); DirectoryEntry newTarget = null; if (entry.IsDirectoryEntry) { newTarget = target.CreateDirectory(entry.Name); IEnumerator entries = ((DirectoryEntry)entry).Entries; while (entries.MoveNext()) { CopyNodeRecursively((Entry)entries.Current, newTarget); } } else { DocumentEntry dentry = (DocumentEntry)entry; using (DocumentInputStream dstream = new DocumentInputStream(dentry)) { target.CreateDocument(dentry.Name, dstream); //now part of usings call to Dispose: dstream.Close(); } } }
/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public DocumentInputStream(DocumentEntry document) { if (!(document is DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; DirectoryNode parentNode = (DirectoryNode)document.Parent; if (documentNode.Document != null) { delegate1 = new ODocumentInputStream(document); } else if (parentNode.FileSystem != null) { delegate1 = new ODocumentInputStream(document); } else if (parentNode.NFileSystem != null) { delegate1 = new NDocumentInputStream(document); } else { throw new IOException("No FileSystem bound on the parent, can't read contents"); } }
public EncryptionHeader(DocumentInputStream dr) { flags = dr.ReadInt(); sizeExtra = dr.ReadInt(); algorithm = dr.ReadInt(); hashAlgorithm = dr.ReadInt(); keySize = dr.ReadInt(); providerType = dr.ReadInt(); dr.ReadLong(); //skip reserved. StringBuilder builder = new StringBuilder(); while (true) { char c = (char)dr.ReadShort(); if (c == 0) break; builder.Append(c); } cspName = builder.ToString(); cipherMode = MODE_ECB; keySalt = null; }
/** * package scoped constructor * * @param stream the DocumentInputStream, freshly opened * @param path the path of the document * @param documentName the name of the document */ public POIFSReaderEvent(DocumentInputStream stream, POIFSDocumentPath path, String documentName) { this.stream = stream; this.path = path; this.documentName = documentName; }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which Contains the actual * data relevant for this class. * * @param poifs POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native CreateFromEmbeddedOleObject(POIFSFileSystem poifs) { bool plain = false; try { poifs.Root.GetEntry("\x0001Ole10ItemName"); plain = true; } catch (FileNotFoundException) { plain = false; } DocumentInputStream dis = poifs.CreateDocumentInputStream(OLE10_NATIVE); using (MemoryStream bos = new MemoryStream()) { IOUtils.Copy(dis, bos); byte[] data = bos.ToArray(); return(new Ole10Native(data, 0, plain)); } }
public ChunkedCipherInputStream(DocumentInputStream dis, long size, AgileDecryptor ag) { try { _size = size; _stream = dis; _ag = ag; _cipher = _ag.GetCipher(_ag.Info.Header.Algorithm, _ag.Info.Header.CipherMode, _ag.SecretKey, _ag.Info.Header.KeySalt); } catch (System.Security.Cryptography.CryptographicException ex) { throw ex; } }
/** * Create an InputStream from the specified Document * * @param document the Document to be read */ public DocumentInputStream(NPOIFSDocument document) { delegate1 = new NDocumentInputStream(document); }
public EncryptionVerifier(DocumentInputStream dis, int encryptedLength) { int saltSize = dis.ReadInt(); if (saltSize != 16) throw new Exception("Salt size != 16 !?"); salt = new byte[16]; dis.ReadFully(salt); verifier = new byte[16]; dis.ReadFully(verifier); verifierHashSize = dis.ReadInt(); verifierHash = new byte[encryptedLength]; dis.ReadFully(verifierHash); spinCount = 50000; algorithm = EncryptionHeader.ALGORITHM_AES_128; cipherMode = EncryptionHeader.MODE_ECB; encryptedKey = null; }