/// <summary> /// Writes the specified value to the PDF stream. /// </summary> public void Write(PdfUInteger value) { WriteSeparator(CharCat.Character); _lastCat = CharCat.Character; WriteRaw(value.Value.ToString(CultureInfo.InvariantCulture)); }
/// <summary> /// Prepares the security handler for encrypting the document. /// </summary> public void PrepareEncryption() { //#if !SILVERLIGHT Debug.Assert(_document._securitySettings.DocumentSecurityLevel != PdfDocumentSecurityLevel.None); var permissions = (uint)Permission; bool strongEncryption; if (_document._securitySettings.DocumentSecurityLevel == PdfDocumentSecurityLevel.Encrypted128BitAes) { strongEncryption = true; Elements[Keys.V] = new PdfInteger(4); Elements[Keys.R] = new PdfInteger(4); CryptFilterDictionary aesCryptFilter = new CryptFilterDictionary(); aesCryptFilter.CFM = CFM.AESV2; aesCryptFilter.Length = 16; PdfDictionary cryptFilters = new PdfDictionary(); cryptFilters.Elements["/StdCF"] = aesCryptFilter; Elements[Keys.CF] = cryptFilters; Elements[Keys.StmF] = new PdfName("/StdCF"); Elements[Keys.StrF] = new PdfName("/StdCF"); } else if (_document._securitySettings.DocumentSecurityLevel == PdfDocumentSecurityLevel.Encrypted128Bit) { strongEncryption = true; Elements[Keys.V] = new PdfInteger(2); Elements[Keys.Length] = new PdfInteger(128); Elements[Keys.R] = new PdfInteger(3); } else { strongEncryption = false; Elements[Keys.V] = new PdfInteger(1); Elements[Keys.Length] = new PdfInteger(40); Elements[Keys.R] = new PdfInteger(2); } if (String.IsNullOrEmpty(_userPassword)) { _userPassword = ""; } // Use user password twice if no owner password provided. if (String.IsNullOrEmpty(_ownerPassword)) { _ownerPassword = _userPassword; } // Correct permission bits permissions |= strongEncryption ? 0xfffff0c0 : 0xffffffc0; permissions &= 0xfffffffc; var pValue = new PdfUInteger(permissions); Debug.Assert(_ownerPassword.Length > 0, "Empty owner password."); byte[] userPad = PadPassword(_userPassword); byte[] ownerPad = PadPassword(_ownerPassword); _md5.Initialize(); _ownerKey = ComputeOwnerKey(userPad, ownerPad, strongEncryption); byte[] documentID = PdfEncoders.RawEncoding.GetBytes(_document.Internals.FirstDocumentID); InitWithUserPassword(documentID, _userPassword, _ownerKey, permissions, strongEncryption); PdfString oValue = new PdfString(PdfEncoders.RawEncoding.GetString(_ownerKey, 0, _ownerKey.Length)); PdfString uValue = new PdfString(PdfEncoders.RawEncoding.GetString(_userKey, 0, _userKey.Length)); Elements[Keys.Filter] = new PdfName("/Standard"); Elements[Keys.O] = oValue; Elements[Keys.U] = uValue; Elements[Keys.P] = pValue; //#endif }
/// <summary> /// Writes the specified value to the PDF stream. /// </summary> public void Write(PdfUInteger value) { WriteSeparator(CharCat.Character); this.lastCat = CharCat.Character; WriteRaw(value.Value.ToString()); }