PDF Security
Dokumentation & Codebeispiele
Linux
MacOS
Windows Client
Windows Server
API
Shell tool (command line)
Watched folder (Windows only)
C/C++
Java
C#
.NET Core
Entwicklerhandbücher & Referenzen
Encryption
Decrypt a PDF document
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Decrypt input file
5 if (!secure.Open(inputPath, password))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Save file
10 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
11 throw new Exception(String.Format("Unable to save document {0}. {1} (ErrorCode: 0x{2:x}).",
12 outputPath, secure.ErrorMessage, secure.ErrorCode));
13
14 // Cleanup
15 secure.Close();
16}
17
1// Create secure object
2secure = new Secure();
3
4// Decrypt input file
5if (!secure.open(inputPath, password))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Save file
10if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
11 throw new IOException(String.format("Unable to save the document %s. %s (ErrorCode: 0x%08x).",
12 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
13
14// Cleanup
15secure.close();
16
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Decrypt input file
5if (!PdfSecureOpen(pSecure, szInputPath, szPassword))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Save file
13if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
14{
15 _tprintf(_T("Unable to save document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
16 iReturnValue = 1;
17 goto cleanup;
18}
19
20// Cleanup
21PdfSecureClose(pSecure);
22
Encrypt a PDF document
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // enable encryption
10 secure.ForceEncryption = true;
11
12 // Encrypt file
13 if (!secure.SaveAs(outputPath, userPassword, ownerPassword, PDFPermission.ePermDigitalPrint |
14 PDFPermission.ePermPrint, 128, "V2", "V2"))
15 throw new Exception(String.Format("Unable to encrypt document {0}. " +
16 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
17
18 // Cleanup
19 secure.Close();
20}
21
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// enable encryption
10secure.setForceEncryption(true);
11
12// Encrypt file
13if (!secure.saveAs(outputPath, userPassword, ownerPassword,
14 NativeLibrary.PERMISSION.ePermDigitalPrint | NativeLibrary.PERMISSION.ePermPrint,
15 128, "V2", "V2"))
16 throw new IOException(String.format("Unable to save the document %s. %s (ErrorCode: 0x%08x).",
17 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
18
19// Cleanup
20secure.close();
21
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Decrypt input file
5if (!PdfSecureOpen(pSecure, szInputPath, _T("")))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Enable encryption
13PdfSecureSetForceEncryption(pSecure, 1);
14
15// Encyrpt file
16if (!PdfSecureSaveAs(pSecure, szOutputPath, szUserPassword, szOwnerPassword, ePermDigitalPrint | ePermPrint, 128, _T("V2"), _T("V2")))
17{
18 _tprintf(_T("Unable to encrypt document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Cleanup
24PdfSecureClose(pSecure);
25
Signing
Mass signing of PDF documents
1using (SessionPool pool = new SessionPool())
2{
3 List<Task> allTasks = new List<Task>();
4 foreach (string inputPath in Directory.GetFiles(inputDir, "*.pdf", SearchOption.AllDirectories))
5 {
6 // Create output directory if it doesn't exist
7 string outputPath = inputPath.Replace(inputDir, outputDir);
8 Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
9
10 // Start signing task
11 Task t = Task.Factory.StartNew(() => Sign(pool, inputPath, outputPath, certificate));
12 allTasks.Add(t);
13 }
14 Task.WaitAll(allTasks.ToArray());
15}
16
1static void Sign(SessionPool pool, string inputPath, string outputPath, string certificate)
2{
3 Secure secure = null;
4 try
5 {
6 // Get session from pool
7 secure = pool.GetSession();
8
9 // Open input file
10 if (!secure.Open(inputPath, ""))
11 throw new Exception(String.Format("Input file {0} cannot be opened. {1} (ErrorCode: 0x{2:x}).",
12 inputPath, secure.ErrorMessage, secure.ErrorCode));
13
14 // Create signature object
15 using (Signature signature = new Signature())
16 {
17 signature.Name = certificate;
18 secure.AddSignature(signature);
19
20 // Sign document
21 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
22 throw new Exception(String.Format("Unable to sign document {0}. {1} (ErrorCode: 0x{2:x}).",
23 inputPath, secure.ErrorMessage, secure.ErrorCode));
24 }
25
26 secure.Close();
27 Console.WriteLine("Document {0} signed successfully.", inputPath);
28 }
29 catch (Exception ex)
30 {
31 Console.WriteLine(ex.Message);
32 }
33 finally
34 {
35 if (secure != null)
36 pool.PutSession(secure);
37 }
38}
1class SessionPool : IDisposable
2{
3 private ConcurrentBag<Secure> sessions = new ConcurrentBag<Secure>();
4
5 public Secure GetSession()
6 {
7 Secure session;
8 if (sessions.TryTake(out session))
9 return session;
10 else
11 session = new Secure();
12
13 if (!session.BeginSession(""))
14 {
15 session.Dispose();
16 throw new Exception(String.Format("Unable to connect to windows cryptographic provider. " +
17 "{0} (ErrorCode: 0x{1:x}).", session.ErrorMessage, session.ErrorCode));
18 }
19 return session;
20 }
21
22 public void PutSession(Secure session)
23 {
24 sessions.Add(session);
25 }
26
27 public void Dispose()
28 {
29 try
30 {
31 int sessionCount = 0;
32 Secure session;
33 while (sessions.TryTake(out session))
34 {
35 session.EndSession();
36 session.Dispose();
37 sessionCount++;
38 }
39 Console.WriteLine("Closed {0} sessions.", sessionCount);
40 }
41 finally
42 {
43 Secure.Terminate();
44 }
45 }
46}
Sign a PDF using Windows Cryptographic Provider
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Begin session with Windows Cryptographic Provider
10 if (!secure.BeginSession(""))
11 throw new Exception(String.Format("Unable to connect to Windows Cryptographic Provider. " +
12 "{0} (ErrorCode: 0x{1:x}).", secure.ErrorMessage, secure.ErrorCode));
13
14 // Create signature object
15 using (Signature signature = new Signature())
16 {
17 signature.Name = certificate;
18 secure.AddSignature(signature);
19
20 // Sign document
21 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
22 throw new Exception(String.Format("Unable to sign document {0}. " +
23 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
24 }
25
26 // Cleanup
27 secure.Close();
28 secure.EndSession();
29}
30
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Begin session with Windows Cryptographic Provider
10if (!secure.beginSession(""))
11 throw new IOException(String.format("Unable to connect to Windows Cryptographic Provider. " +
12 "%s (ErrorCode: 0x%08x).", secure.getErrorMessage(), secure.getErrorCode()));
13
14// Create signature object
15signature = new Signature();
16
17signature.setName(certificate);
18secure.addSignature(signature);
19
20// Sign document
21if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
22 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x).",
23 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
24
25// Cleanup
26secure.close();
27secure.endSession();
28
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Open input file
5if (!PdfSecureOpen(pSecure, szInputPath, _T("")))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Begin session with Windows Cryptographic Provider
13if (!PdfSecureBeginSession(pSecure, _T("")))
14{
15 _tprintf(_T("Unable to connect to Windows Cryptographic Provider. %s (ErrorCode: 0x%08x).\n"), PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
16 iReturnValue = 1;
17 goto cleanup;
18}
19
20// Create signature object
21pSignature = PdfSignatureCreateObject();
22
23PdfSignatureSetName(pSignature, szCertificate);
24PdfSecureAddSignature(pSecure, pSignature);
25
26// Sign document
27if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
28{
29 _tprintf(_T("Unable to sign document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
30 iReturnValue = 1;
31 goto cleanup;
32}
33
34// Cleanup
35PdfSecureClose(pSecure);
36
Sign a PDF using DigiCert-QuoVadis sealsign
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Required: unique name of the accountspecified on the server.
10 secure.SetSessionPropertyString("Identity", "Rigora");
11 // Required: identifies the signature specifications by a unique name.
12 secure.SetSessionPropertyString("Profile", "Default");
13 // Required: password which secures the access to the account.
14 secure.SetSessionPropertyString("secret", "NeE=EKEd33FeCk70");
15 // Required: helps to separate access and to create better statistics.
16 secure.SetSessionPropertyString("clientId", "3949-4929-3179-2818");
17 // Required: activates the signing key.
18 secure.SetSessionPropertyString("pin", "123456");
19 // Optional: default value "SHA-256"
20 secure.SetSessionPropertyString("MessageDigestAlgorithm", "SHA-256");
21
22 // Begin session using DigiCert-QuoVadis Sealsign (demo version)
23 if (!secure.BeginSession(@"https://services.sealsignportal.com/sealsign/ws/BrokerClient"))
24 throw new Exception(String.Format("Unable to establish connection to DigiCert-QuoVadis Sealsign. " +
25 "{0} (ErrorCode: 0x{1:x}).", secure.ErrorMessage, secure.ErrorCode));
26
27 // Add signature
28 using (Signature signature = new Signature())
29 {
30 // Required, name of the signer
31 signature.Name = "Rigora";
32 secure.AddSignature(signature);
33 }
34
35 // Sign document
36 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
37 throw new Exception(String.Format("Unable to sign document {0}. {1} (ErrorCode: 0x{2:x}).",
38 outputPath, secure.ErrorMessage, secure.ErrorCode));
39
40 // Cleanup
41 secure.Close();
42 secure.EndSession();
43}
44
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Required: unique name of the account specified on the server.
10secure.setSessionPropertyString("Identity", "Rigora");
11// Required: identifies the signature specifications by a unique name.
12secure.setSessionPropertyString("Profile", "Default");
13// Required: password which secures the access to the account.
14secure.setSessionPropertyString("secret", "NeE=EKEd33FeCk70");
15// Required: helps to separate access and to create better statistics.
16secure.setSessionPropertyString("clientId", "3949-4929-3179-2818");
17// Required: activates the signing key.
18secure.setSessionPropertyString("pin", "123456");
19// Optional: default value "SHA-256"
20secure.setSessionPropertyString("MessageDigestAlgorithm", "SHA-256");
21
22// Begin session using DigiCert-QuoVadis Sealsign (demo version)
23if (!secure.beginSession("https://services.sealsignportal.com/sealsign/ws/BrokerClient"))
24 throw new IOException(String.format("Unable to establish connection to DigiCert-QuoVadis Sealsign. " +
25 "%s (ErrorCode: 0x%08x).", secure.getErrorMessage(), secure.getErrorCode()));
26
27// Add signature
28signature = new Signature();
29
30// Required, name of the signer
31signature.setName("Rigora");
32secure.addSignature(signature);
33
34// Sign document
35if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
36 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x).",
37 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
38
39// Cleanup
40secure.close();
41secure.endSession();
42
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Open input file
5if (!PdfSecureOpen(pSecure, szInputPath, _T("")))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Required: unique name of the accountspecified on the server.
13PdfSecureSetSessionPropertyString(pSecure, _T("Identity"), _T("Rigora"));
14// Required: identifies the signature specifications by a unique name.
15PdfSecureSetSessionPropertyString(pSecure, _T("Profile"), _T("Default"));
16// Required: password which secures the access to the account.
17PdfSecureSetSessionPropertyString(pSecure, _T("secret"), _T("NeE=EKEd33FeCk70"));
18// Required: helps to separate access and to create better statistics.
19PdfSecureSetSessionPropertyString(pSecure, _T("clientId"), _T("3949-4929-3179-2818"));
20// Required: activates the signing key.
21PdfSecureSetSessionPropertyString(pSecure, _T("pin"), _T("123456"));
22// Optional: default value "SHA-256"
23PdfSecureSetSessionPropertyString(pSecure, _T("MessageDigestAlgorithm"), _T("SHA-256"));
24
25// Begin session using DigiCert-QuoVadis Sealsign (demo version)
26if (!PdfSecureBeginSession(pSecure, _T("https://services.sealsignportal.com/sealsign/ws/BrokerClient")))
27{
28 _tprintf(_T("Unable to connect to DigiCert-QuoVadis Sealsign. %s (ErrorCode: 0x%08x).\n"), PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
29 iReturnValue = 1;
30 goto cleanup;
31}
32
33// Create signature object
34pSignature = PdfSignatureCreateObject();
35
36// Add signature
37// Required, name of the signer
38PdfSignatureSetName(pSignature, _T("Rigora"));
39PdfSecureAddSignature(pSecure, pSignature);
40
41// Sign document
42if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
43{
44 _tprintf(_T("Unable to sign document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
45 iReturnValue = 1;
46 goto cleanup;
47}
48
49// Cleanup
50PdfSecureClose(pSecure);
51PdfSecureEndSession(pSecure);
52
Sign a PDF using GlobalSign Digital Signing Service
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Required: insert your account credentials’ key parameter for the login request
10 secure.SetSessionPropertyString("api_key", "****fill in****");
11 // Required: insert your account credentials’ secret parameter for the login request
12 secure.SetSessionPropertyString("api_secret", "****fill in****");
13 // Required: parameter to create the signing certificate
14 secure.SetSessionPropertyString("Identity", "{ }");
15 // Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
16 secure.SetSessionPropertyBytes("SSLClientCertificate", File.ReadAllBytes("****fill in****"));
17 // Optional: password to decrypt the private key of theSSL client certificate
18 secure.SetSessionPropertyString("SSLClientCertificatePassword", "****fill in****");
19 // Recommended: The server's SSL certificate or its issuer (CA) certificate.
20 secure.SetSessionPropertyBytes("SSLServerCertificate", File.ReadAllBytes("globalsign-root-ca.cer"));
21
22 // Begin session using GlobalSign Digital Signing Service
23 if (!secure.BeginSession("https://emea.api.dss.globalsign.com:8443/v2"))
24 throw new Exception(String.Format("Unable to establish connection to GlobalSign Digital " +
25 "Signing Service. {0} (ErrorCode: 0x{1:x}).", secure.ErrorMessage, secure.ErrorCode));
26
27 // Add signature
28 using (Signature signature = new Signature())
29 {
30 // Required, name of the signer
31 signature.Name = signatureName;
32 signature.TimeStampURL = "urn:ietf:rfc:3161";
33 secure.AddSignature(signature);
34 }
35
36 // Sign document
37 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
38 throw new Exception(String.Format("Unable to sign document {0}. {1} (ErrorCode: 0x{2:x}).",
39 outputPath, secure.ErrorMessage, secure.ErrorCode));
40
41 // Cleanup
42 secure.Close();
43 secure.EndSession();
44}
45
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Required: insert your account credentials' key parameter for the login request
10secure.setSessionPropertyString("api_key", "*****fill in*****");
11// Required: insert your account credentials' secret parameter for the login request
12secure.setSessionPropertyString("api_secret", "*****fill in*****");
13// Required: parameter to create the signing certificate
14secure.setSessionPropertyString("Identity", "{ }");
15// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
16secure.setSessionPropertyBytes("SSLClientCertificate",
17 Files.readAllBytes(Paths.get("*****fil in*****")));
18// Optional: password to decrypt the private key of theSSL client certificate
19secure.setSessionPropertyString("SSLClientCertificatePassword", "*****fill in*****");
20// Recommended: server's SSL certificate or its issuer (CA) certificate.
21secure.setSessionPropertyBytes("SSLServerCertificate",
22 Files.readAllBytes(Paths.get("globalsign-root-ca.cer")));
23
24// Begin session using GlobalSign Digital Signing Service
25if (!secure.beginSession("https://emea.api.dss.globalsign.com:8443/v2"))
26 throw new IOException(String.format("Unable to establish connection to GlobalSign Digital " +
27 "Signing Service. %s (ErrorCode: 0x%08x).", secure.getErrorMessage(),
28 secure.getErrorCode()));
29
30// Add signature
31signature = new Signature();
32
33// Required, name of the signer
34signature.setName(signatureName);
35signature.setTimeStampURL("urn:ietf:rfc:3161");
36secure.addSignature(signature);
37
38// Sign document
39if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
40 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x).",
41 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
42
43// Cleanup
44secure.close();
45secure.endSession();
46
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Open input file
5if (!PdfSecureOpen(pSecure, szInputPath, _T("")))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Required: insert your account credentials’ key parameter for the login request
13PdfSecureSetSessionPropertyString(pSecure, _T("api_key"), _T("****fill in****"));
14// Required: insert your account credentials’ secret parameter for the login request
15PdfSecureSetSessionPropertyString(pSecure, _T("api_secret"), _T("****fill in****"));
16// Required: parameter to create the signing certificate
17PdfSecureSetSessionPropertyString(pSecure, _T("Identity"), _T("{ }"));
18// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
19PdfSecureSetSessionPropertyString(pSecure, _T("SSLClientCertificate"), _T("****fill in****"));
20// Optional: password to decrypt the private key of theSSL client certificate
21PdfSecureSetSessionPropertyString(pSecure, _T("SSLClientCertificatePassword"), _T("****fill in****"));
22// Recommended: path to server's SSL certificate or its issuer (CA) certificate.
23PdfSecureSetSessionPropertyString(pSecure, _T("SSLServerCertificate"), _T("globalsign-root-ca.cer"));
24
25// Begin session using GlobalSign Digital Signing Service
26if (!PdfSecureBeginSession(pSecure, _T("https://emea.api.dss.globalsign.com:8443/v2")))
27{
28 _tprintf(_T("Unable to connect to GlobalSign Digital Signing Service. %s (ErrorCode: 0x%08x).\n"), PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
29 iReturnValue = 1;
30 goto cleanup;
31}
32
33// Create signature object
34pSignature = PdfSignatureCreateObject();
35
36// Add signature
37// Required, name of the signer
38PdfSignatureSetName(pSignature, szSignatureName);
39PdfSignatureSetTimeStampURL(pSignature, _T("urn:ietf:rfc:3161"));
40
41PdfSecureAddSignature(pSecure, pSignature);
42
43// Sign document
44if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
45{
46 _tprintf(_T("Unable to sign document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
47 iReturnValue = 1;
48 goto cleanup;
49}
50
51// Cleanup
52PdfSecureClose(pSecure);
53PdfSecureEndSession(pSecure);
54
Sign a PDF using myBica Digital Signing Service
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Required: set identity of the signing certificate
10 secure.SetSessionPropertyString("Identity", "****fill in****");
11 // Required: set DSSProfile
12 secure.SetSessionPropertyString("DSSProfile", "http://www.pdf-tools.com/dss/profile/pades/1.0");
13 // Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
14 secure.SetSessionPropertyBytes("SSLClientCertificate", File.ReadAllBytes("****fill in****"));
15 // Optional: set password to decrypt the private key of the SSL client certificate
16 secure.SetSessionPropertyString("SSLClientCertificatePassword", "****fill in****");
17 // Recommended: Path to server's SSL certificate or its issuer (CA) certificate.
18 secure.SetSessionPropertyString("SSLServerCertificate", "swisssign-root-ca.cer");
19
20 // Create a Request-ID
21 Guid requestId = Guid.NewGuid();
22 secure.SetSessionPropertyString("RequestID", requestId.ToString("D"));
23
24 // Begin session using myBica Digital Signing Service
25 if (!secure.BeginSession(@"https://sign.mybica.ch/DS/DS"))
26 throw new Exception(String.Format("Unable to establish connection to myBica Digital " +
27 "Signing Service. {0} (ErrorCode: 0x{1:x}).", secure.ErrorMessage, secure.ErrorCode));
28
29 // Add signature
30 using (Signature signature = new Signature())
31 {
32 // Required, name of signer
33 signature.Name = "****fill in****";
34 signature.TimeStampURL = "urn:ietf:rfc:3161";
35 secure.AddSignature(signature);
36 }
37
38 // Sign document
39 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
40 throw new Exception(String.Format("Unable to sign document {0}. {1} (ErrorCode: 0x{2:x}, " +
41 "Request-ID: {3}).", outputPath, secure.ErrorMessage, secure.ErrorCode, requestId));
42
43 // Cleanup
44 secure.Close();
45 secure.EndSession();
46}
47
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Required: set identity of the signing certificate
10secure.setSessionPropertyString("Identity", "*****fill in*****");
11// Required: set DSSProfile
12secure.setSessionPropertyString("DSSProfile", "http://www.pdf-tools.com/dss/profile/pades/1.0");
13// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
14secure.setSessionPropertyBytes("SSLClientCertificate",
15 Files.readAllBytes(Paths.get("*****fill in*****")));
16// Optional: set password to decrypt the private key of the SSL client certificate
17secure.setSessionPropertyString("SSLClientCertificatePassword", "*****fill in*****");
18// Recommended: Path to server's SSL certificate or its issuer (CA) certificate.
19secure.setSessionPropertyString("SSLServerCertificate", "swisssign-root-ca.cer");
20
21// Create a Request-ID
22UUID requestId = UUID.randomUUID();
23secure.setSessionPropertyString("RequestID", requestId.toString());
24
25// Begin session using myBica Digital Signing Service
26if (!secure.beginSession("https://sign.mybica.ch/DS/DS"))
27 throw new IOException(String.format("Unable to establish connection to myBica Digital" +
28 "Signing Service. %s (ErrorCode: 0x%08x).", secure.getErrorMessage(),
29 secure.getErrorCode()));
30
31// Add signature
32signature = new Signature();
33
34// Required, name of the signer
35signature.setName("****fill in****");
36signature.setTimeStampURL("urn:ietf:rfc:3161");
37secure.addSignature(signature);
38
39// Sign document
40if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
41 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x, " +
42 "Request-ID: %s).", outputPath, secure.getErrorMessage(), secure.getErrorCode(),
43 requestId));
44
45// Cleanup
46secure.close();
47secure.endSession();
48
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Open input file
5if (!PdfSecureOpen(pSecure, szInputPath, _T("")))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Required: insert missing value ‹customer name›:‹key identity›
13PdfSecureSetSessionPropertyString(pSecure, _T("Identity"), _T("****fill in****"));
14// Required: set DSSProfile
15PdfSecureSetSessionPropertyString(pSecure, _T("DSSProfile"), _T("http://www.pdf-tools.com/dss/profile/pades/1.0"));
16// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
17PdfSecureSetSessionPropertyString(pSecure, _T("SSLClientCertificate"), _T("****fill in****"));
18// Optional: insert password to decrypt the private key of the SSL client certificate
19PdfSecureSetSessionPropertyString(pSecure, _T("SSLClientCertificatePassword"), _T("****fill in****"));
20// Recommended: Path to server's SSL certificate or its issuer (CA) certificate.
21PdfSecureSetSessionPropertyString(pSecure, _T("SSLServerCertificate"), _T("swisssign-root-ca.cer"));
22// Recommended, insert any string that can be used to track the request, e.g. an UUID
23PdfSecureSetSessionPropertyString(pSecure, _T("RequestID"), _T("1"));
24
25// Begin session using myBica Digital Signing Service
26if (!PdfSecureBeginSession(pSecure, _T("https://sign.mybica.ch/DS/DS")))
27{
28 _tprintf(_T("Unable to connect to myBica Digital Signing Service. %s (ErrorCode: 0x%08x).\n"), PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
29 iReturnValue = 1;
30 goto cleanup;
31}
32
33// Create signature object
34pSignature = PdfSignatureCreateObject();
35
36// Add signature
37// Required, name of the signer
38PdfSignatureSetName(pSignature, _T("****fill in****"));
39PdfSignatureSetTimeStampURL(pSignature, _T("urn:ietf:rfc:3161"));
40PdfSecureAddSignature(pSecure, pSignature);
41
42// Sign document
43if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
44{
45 _tprintf(_T("Unable to sign document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
46 iReturnValue = 1;
47 goto cleanup;
48}
49
50// Cleanup
51PdfSecureClose(pSecure);
52PdfSecureEndSession(pSecure);
53
Sign a PDF using PKCS#11 Provider
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Begin session using PKCS#11
10 // General: "PathToDll;SlotId;Pin"
11 if (!secure.BeginSession("****fill in****"))
12 throw new Exception(String.Format("Unable to connect to PKCS#11. {0} (ErrorCode: 0x{1:x}).",
13 secure.ErrorMessage, secure.ErrorCode));
14
15 // Create signature object
16 using (Signature signature = new Signature())
17 {
18 signature.Name = certificate;
19 secure.AddSignature(signature);
20
21 // Sign document
22 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
23 throw new Exception(String.Format("Unable to sign document {0}. " +
24 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
25 }
26
27 // Cleanup
28 secure.Close();
29 secure.EndSession();
30}
31
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Begin session using PKCS#11
10// General: "PathToDll;SlotId;Pin"
11if (!secure.beginSession("*****fill in*****"))
12 throw new IOException(String.format("Unable to connect to PKCS#11. %s (ErrorCode: 0x%08x).",
13 secure.getErrorMessage(), secure.getErrorCode()));
14
15// Create signature object
16signature = new Signature();
17
18signature.setName(certificate);
19secure.addSignature(signature);
20
21// Sign document
22if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
23 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x).",
24 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
25
26// Cleanup
27secure.close();
28secure.endSession();
29
1// Create secure object
2pSecure = PdfSecureCreateObject();
3
4// Open input file
5if (!PdfSecureOpen(pSecure, szInputPath, _T("")))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Begin session using PKCS#11
13// General: "PathToDll;SlotId;Pin"
14if (!PdfSecureBeginSession(pSecure, "****fill in****"))
15{
16 _tprintf(_T("Unable to connect to PKCS#11. %s (ErrorCode: 0x%08x).\n"), PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
17 iReturnValue = 1;
18 goto cleanup;
19}
20
21// Create signature object
22pSignature = PdfSignatureCreateObject();
23PdfSignatureSetName(pSignature, szCertificate);
24PdfSecureAddSignature(pSecure, pSignature);
25
26// Sign document
27if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
28{
29 _tprintf(_T("Unable to sign document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
30 iReturnValue = 1;
31 goto cleanup;
32}
33
34// Cleanup
35PdfSecureClose(pSecure);
36
Sign PDF using Swisscom All-in Signing Service
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5 if (!secure.Open(inputPath, ""))
6 throw new Exception(String.Format("Input file {0} cannot be opened. " +
7 "{1} (ErrorCode: 0x{2:x}).", inputPath, secure.ErrorMessage, secure.ErrorCode));
8
9 // Required: insert missing value ‹customer name›:‹key identity›
10 secure.SetSessionPropertyString("Identity", "****fill in****");
11 // Required: set DSSProfile
12 secure.SetSessionPropertyString("DSSProfile", "http://ais.swisscom.ch/1.0");
13 // Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
14 secure.SetSessionPropertyBytes("SSLClientCertificate", File.ReadAllBytes(@"****fill in****"));
15 // Optional: insert password to decrypt the private key of the SSL client certificate
16 secure.SetSessionPropertyString("SSLClientCertificatePassword", "****fill in****");
17 // Recommended: set server's SSL certificate or its issuer (CA) certificate.
18 secure.SetSessionPropertyBytes("SSLServerCertificate", File.ReadAllBytes("ais.swisscom-root-ca.cer"));
19
20 // Create a Request-ID
21 Guid requestId = Guid.NewGuid();
22 secure.SetSessionPropertyString("RequestID", requestId.ToString("D"));
23
24 // Begin session using Swisscom All-in Signing Service
25 if (!secure.BeginSession(@"https://ais.swisscom.com/AIS-Server/rs/v1.0/sign"))
26 throw new Exception(String.Format("Unable to establish connection to Swisscom All-in " +
27 "Signing Service. {0} (ErrorCode: 0x{1:x}).", secure.ErrorMessage, secure.ErrorCode));
28
29 // Add signature
30 using (Signature signature = new Signature())
31 {
32 // Required, name of the signer
33 signature.Name = "****fill in****";
34 secure.AddSignature(signature);
35 }
36
37 // Sign document
38 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
39 throw new Exception(String.Format("Unable to sign document {0}. {1} (ErrorCode: 0x{2:x}, " +
40 "Request-ID: {3}).", outputPath, secure.ErrorMessage, secure.ErrorCode, requestId));
41
42 // Cleanup
43 secure.Close();
44 secure.EndSession();
45}
46
1// Create secure object
2secure = new Secure();
3
4// Open input file
5if (!secure.open(inputPath, ""))
6 throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Required: insert missing value ‹customer name›:‹key identity›
10secure.setSessionPropertyString("Identity", "*****fill in****");
11// Required: set DSSProfile
12secure.setSessionPropertyString("DSSProfile", "http://ais.swisscom.ch/1.0");
13// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
14secure.setSessionPropertyBytes("SSLClientCertificate",
15 Files.readAllBytes(Paths.get("*****fill in*****")));
16// Optional: insert password to decrypt the private key of the SSL client certificate
17secure.setSessionPropertyString("SSLClientCertificatePassword", "*****fill in*****");
18// Recommended: set server's SSL certificate or its issuer (CA) certificate.
19secure.setSessionPropertyBytes("SSLServerCertificate",
20 Files.readAllBytes(Paths.get("ais.swisscom-root-ca.cer")));
21
22// Create a Request-ID
23UUID requestId = UUID.randomUUID();
24secure.setSessionPropertyString("RequestID", requestId.toString());
25
26// Begin session using Swisscom All-in Signing Service
27if (!secure.beginSession("https://ais.swisscom.com/AIS-Server/rs/v1.0/sign"))
28 throw new IOException(String.format("Unable to establish connection to Swisscom All-in " +
29 "Signing Service. %s (ErrorCode: 0x%08x).", secure.getErrorMessage(),
30 secure.getErrorCode()));
31
32// Add signature
33signature = new Signature();
34
35// Required, name of the signer
36signature.setName("****fill in****");
37secure.addSignature(signature);
38
39// Sign document
40if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
41 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x, "