Ejemplo n.º 1
0
 /**
  * This will encrypt a string.
  *
  * @param string the string to encrypt.
  * @param objNum The object number.
  * @param genNum The object generation number.
  *
  * @throws IOException If an error occurs writing the new string.
  */
 public void EncryptString(PdfString pdfString, long objNum, int genNum)
 {
     using (var data = new MemoryStream(pdfString.GetBuffer()))
         using (var buffer = new MemoryStream())
         {
             if (EncryptData(objNum, genNum, data, buffer, false /* encrypt */))
             {
                 pdfString.SetBuffer(buffer.GetBuffer());
             }
         }
 }
Ejemplo n.º 2
0
        /**
         * This will decrypt a string.
         *
         * @param string the string to decrypt.
         * @param objNum The object number.
         * @param genNum The object generation number.
         *
         * @throws IOException If an error occurs writing the new string.
         */
        private void DecryptString(PdfString pdfString, long objNum, long genNum)
        {
            // String encrypted with identity filter
            if (PdfName.Identity.Equals(stringFilterName))
            {
                return;
            }

            using (var data = new MemoryStream(pdfString.GetBuffer()))
                using (var outputStream = new MemoryStream())
                {
                    try
                    {
                        if (EncryptData(objNum, genNum, data, outputStream, true /* decrypt */))
                        {
                            pdfString.SetBuffer(outputStream.ToArray());
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"error: Failed to decrypt PdfString of Length {pdfString.GetBuffer().Length} in object {objNum}: {ex.Message}", ex);
                    }
                }
        }