internal virtual PDFEncrypterFactory GetEncrypterFactory() { PDFEncrypterFactory factory = PDFEncrypterFactory.CreateFactory(this.Version, this.Revision); if (null == factory) { throw new PDFSecurityException(string.Format("There is no available encryptor for the version and revision " + this.Version + "." + this.Revision)); } return(factory); }
//implementation methods protected override PDFWriter DoGetInstance(Document forDoc, Stream stream, int generation, PDFDocumentRenderOptions options, PDFTraceLog log) { if (null == forDoc.DocumentID) { forDoc.DocumentID = PDFDocumentID.Create(); } PDFEncrypterFactory factory = this.GetEncrypterFactory(); IDocumentPasswordSettings settings; string path = forDoc.LoadedSource; SecureString owner; SecureString user; PermissionFlags protection; if (Options.SecurityOptions.TryGetPasswordSettings(path, out settings)) { owner = settings.OwnerPassword; user = settings.UserPassword; protection = settings.DefaultPermissions; if (settings.AllowDocumentOverrides) { if (null != this.OwnerPassword) { owner = this.OwnerPassword; } if (null != this.UserPassword) { user = this.UserPassword; } protection |= this.GetRestrictions(); } } else { protection = this.GetRestrictions(); owner = this.OwnerPassword; user = this.UserPassword; } PDFEncryter enc = factory.InitEncrypter(owner, user, forDoc.DocumentID, protection); PDFSecureWriter14 writer = new PDFSecureWriter14(stream, log, enc); return(writer); }