PdfFileSecurity.EncryptFile

EncryptFile(string, string, DocumentPrivilege, KeySize)

使用用户密码和所有者密码加密 Pdf 文件,并设置文档的访问权限。用户密码和所有者密码可以为 null 或空。如果输入的所有者密码为 null 或空,则所有者密码将被随机字符串替换。如果处理失败,将抛出异常。

public bool EncryptFile(string userPassword, string ownerPassword, DocumentPrivilege privilege, 
    KeySize keySize)
参数类型描述
userPasswordString用户密码。
ownerPasswordString所有者密码。
privilegeDocumentPrivilege设置权限。
keySizeKeySizeKeySize.x40 用于 40 位加密,KeySize.x128 用于 128 位加密,KeySize.x256 用于 256 位加密。

返回值

成功返回 true。

示例

[C#]
string inFile = "D:\\input.pdf"; //The TestPath may be re-assigned.
string outFile = "D:\\output.pdf"; //The TestPath may be re-assigned.	
PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile);		
fileSecurity.EncryptFile("userpass", "ownerpass", DocumentPrivilege.Print, KeySize.x256);	

[Visual Basic]
Dim inFile As String = "D:\\input.pdf"  'The TestPath may be re-assigned.'
Dim outFile As String = "D:\\output.pdf"   'The TestPath may be re-assigned.'
Dim fileSecurity As PdfFileSecurity = New PdfFileSecurity(inFile,outFile) 
fileSecurity.EncryptFile("userpass", "ownerpass", DocumentPrivilege.Print, KeySize.x256)

另请参阅


EncryptFile(string, string, DocumentPrivilege, KeySize, Algorithm)

使用用户密码和所有者密码加密 Pdf 文件,并设置文档的访问权限。用户密码和所有者密码可以为 null 或空。如果输入的所有者密码为 null 或空,则所有者密码将被随机字符串替换。KeySize 和 Algorithm 值有 6 种可能的组合。然而 (KeySize.x40, Algorithm.AES) 和 (KeySize.x256, Algorithm.RC4) 是无效的,如果遇到这种组合,将引发相应的异常。如果处理失败,将抛出异常。

public bool EncryptFile(string userPassword, string ownerPassword, DocumentPrivilege privilege, 
    KeySize keySize, Algorithm cipher)
参数类型描述
userPasswordString用户密码。
ownerPasswordString所有者密码。
privilegeDocumentPrivilege设置权限。
keySizeKeySizeKeySize.x40 用于 40 位加密,KeySize.x128 用于 128 位加密,KeySize.x256 用于 256 位加密。
cipherAlgorithmAlgorithm.AES 使用 AES 算法加密或 Algorithm.RC4 进行 RC4 加密。

返回值

成功返回 true。

示例

[C#]
string inFile = "D:\\input.pdf"; //The TestPath may be re-assigned.
string outFile = "D:\\output.pdf"; //The TestPath may be re-assigned.	
PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile);		
fileSecurity.EncryptFile("userpass","ownerpass",DocumentPrivilege.Print,KeySize.x256,Algorithm.AES);	

[Visual Basic]
Dim inFile As String = "D:\\input.pdf"  'The TestPath may be re-assigned.'
Dim outFile As String = "D:\\output.pdf"   'The TestPath may be re-assigned.'
Dim fileSecurity As PdfFileSecurity =  New PdfFileSecurity(inFile,outFile) 
fileSecurity.EncryptFile("userpass","ownerpass",DocumentPrivilege.Print,KeySize.x256,Algorithm.AES)

另请参阅