Namespace DocWright.Cryptography
Classes
- AgileEncryptionSettings
How to encrypt a package. Defaults match what Word writes, so a file DocWright encrypts with no settings supplied is indistinguishable in shape from one Word produced.
- CryptographicRandomSource
The default IRandomSource: the platform's cryptographic random number generator.
- DocumentProtectionHash
Computes and checks the password hashes on
w:documentProtectionandw:writeProtection.These hashes are not a security boundary and DocWright does not treat them as one. Protection settings are a user-interface convenience: Word asks for the password before letting a person edit, and any program that ignores the setting edits anyway — including DocWright, which reports protection and never enforces it. What this class provides is the ability to answer "is this the password the document records?", and to record a new one.
- EncryptedOfficePackage
An encrypted Office document: a Compound File Binary container holding an
EncryptionInfodescriptor and anEncryptedPackagestream whose plaintext is an ordinary OOXML zip.This is what a password-protected .docx actually is on disk. It carries no zip signature, which is why a reader that sniffs for
PK\x03\x04declines it and the caller ends up with a puzzling "not a valid package" error instead of "supply a password".
- EncryptionInfoDescriptor
The version header of an
EncryptionInfostream, which is what identifies the scheme ([MS-OFFCRYPTO] §2.3.4.5). The rest of the stream is scheme-specific and is parsed by the scheme's own reader.
- LegacyBinaryDecryptor
Decrypts the streams of a legacy binary Office document — a Word 97-2003
.docand its siblings — which are encrypted stream by stream rather than as a single package.
- OfficeDecryptor
Decrypts an EncryptedOfficePackage into the ordinary OOXML package it contains, so an existing reader can take it from there.
Decryption is a pre-processing step, not a format: the plaintext is a .docx, .xlsx or .pptx exactly as it would have been written unencrypted, and DocWright hands it to whichever reader recognizes it.
- OfficeEncryptor
Wraps a plaintext OOXML package in ECMA-376 agile encryption, producing the compound file Word expects.
- OfficeHashAlgorithm
Maps the algorithm names used in ECMA-376 encryption and protection descriptors onto BCL implementations.
Interfaces
- IRandomSource
The source of the salts, initialization vectors and keys an encryption pass needs.
This seam exists so tests can be deterministic. Everything else DocWright writes is byte-identical across runs; encryption cannot be, because reusing a salt would defeat it. Injecting the randomness moves that boundary somewhere a test can stand on rather than abandoning the guarantee.
A production caller should never supply one. A predictable implementation makes the output trivially breakable.
Enums
- OfficeEncryptionScheme
The encryption scheme an
EncryptionInfostream declares, as identified from its version pair and flags ([MS-OFFCRYPTO] §2.3.4).
- OfficeHashAlgorithmKind
The hash algorithms an Office encryption descriptor may name.
- ProtectionHashKind
Which of the two spellings of a protection password hash a document uses.