iTextSharp.text.pdf.PdfEncryption.SetCryptoMode C# (CSharp) Метод

SetCryptoMode() публичный Метод

public SetCryptoMode ( int mode, int kl ) : void
mode int
kl int
Результат void
        public void SetCryptoMode(int mode, int kl)
        {
            cryptoMode = mode;
            encryptMetadata = (mode & PdfWriter.DO_NOT_ENCRYPT_METADATA) != PdfWriter.DO_NOT_ENCRYPT_METADATA;
            embeddedFilesOnly = (mode & PdfWriter.EMBEDDED_FILES_ONLY) == PdfWriter.EMBEDDED_FILES_ONLY;
            mode &= PdfWriter.ENCRYPTION_MASK;
            switch (mode) {
            case PdfWriter.STANDARD_ENCRYPTION_40:
                encryptMetadata = true;
                embeddedFilesOnly = false;
                keyLength = 40;
                revision = STANDARD_ENCRYPTION_40;
                break;
            case PdfWriter.STANDARD_ENCRYPTION_128:
                embeddedFilesOnly = false;
                if (kl > 0)
                    keyLength = kl;
                else
                    keyLength = 128;
                revision = STANDARD_ENCRYPTION_128;
                break;
            case PdfWriter.ENCRYPTION_AES_128:
                keyLength = 128;
                revision = AES_128;
                break;
            case PdfWriter.ENCRYPTION_AES_256:
                keyLength = 256;
                keySize = 32;
                revision = AES_256;
                break;
            default:
                throw new ArgumentException(MessageLocalization.GetComposedMessage("no.valid.encryption.mode"));
            }
        }

Usage Example

Пример #1
0
 /**
 * Sets the certificate encryption options for this document. An array of one or more public certificates
 * must be provided together with an array of the same size for the permissions for each certificate.
 *  The open permissions for the document can be
 *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
 *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
 *  The permissions can be combined by ORing them.
 * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
 * @param certs the public certificates to be used for the encryption
 * @param permissions the user permissions for each of the certicates
 * @param encryptionType the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
 * @throws DocumentException if the document is already open
 */
 public void SetEncryption(X509Certificate[] certs, int[] permissions, int encryptionType) {
     if (pdf.IsOpen())
         throw new DocumentException(MessageLocalization.GetComposedMessage("encryption.can.only.be.added.before.opening.the.document"));
     crypto = new PdfEncryption();
     if (certs != null) {
         for (int i=0; i < certs.Length; i++) {
             crypto.AddRecipient(certs[i], permissions[i]);
         }
     }
     crypto.SetCryptoMode(encryptionType, 0);
     crypto.GetEncryptionDictionary();
 }
All Usage Examples Of iTextSharp.text.pdf.PdfEncryption::SetCryptoMode