Code samples
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, " +
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://ais.swisscom.ch/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("ais.swisscom-root-ca.cer"));
22// Recommended, insert any string that can be used to track the request
23PdfSecureSetSessionPropertyString(pSecure, _T("RequestID"), _T("AE57F021-C0EB-4AE0-8E5E-67FB93E5BC7F"));
24
25// Begin session using Swisscom All-in Signing Service
26if (!PdfSecureBeginSession(pSecure, _T("https://ais.swisscom.com/AIS-Server/rs/v1.0/sign")))
27{
28 _tprintf(_T("Unable to connect to Swisscom All-in 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****"));
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 SwissSign SuisseID 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: SAML token issued by the SuisseID Identity Provider (IDP)
10 secure.SetSessionPropertyString("SAMLToken", samlToken);
11 // Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
12 secure.SetSessionPropertyBytes("SSLClientCertificate", File.ReadAllBytes("****fill in****"));
13 // Optional: password to decrypt the private key of the SSL client certificate
14 secure.SetSessionPropertyString("SSLClientCertificatePassword", "****fill in****");
15 // Recommended: Path to server's SSL certificate or its issuer (CA) certificate.
16 secure.SetSessionPropertyString("SSLServerCertificate", "swisssign-root-ca.cer");
17
18 // Begin session using SwissSign SuisseID Signing Service
19 if (!secure.BeginSession("https://sig.post.ch/sigaas/?SuisseID"))
20 throw new Exception(String.Format("Unable to establish connection to SwissSign SuisseID " +
21 "Signing Service. {0} (ErrorCode: 0x{1:x}).", secure.ErrorMessage, secure.ErrorCode));
22
23 // Add signature and time-stamp
24 using (Signature signature = new Signature())
25 {
26 // Required, name of signer
27 signature.Name = signatureName;
28 signature.TimeStampURL = "http://tsa.swisssign.net";
29 signature.Reason = "Document reviewed!";
30 signature.Text1 = "\t10,44 " + signature.Name;
31 signature.FontSize1 = 15;
32 signature.FontSize2 = 6;
33 signature.ImageFileName = "DigitalSignature.jpg";
34 signature.PageNo = 1;
35 signature.Rect = new PDFRect(10.0f, 10.0f, 145.0f, 86.0f);
36
37 secure.AddSignature(signature);
38 }
39
40 // Sign document
41 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
42 throw new Exception(String.Format("Unable to sign document {0}. {1} (ErrorCode: 0x{2:x}).",
43 outputPath, secure.ErrorMessage, secure.ErrorCode));
44
45 // Cleanup
46 secure.Close();
47 secure.EndSession();
48}
49
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: SAML token issued by the SuisseID Identity Provider (IDP)
10secure.setSessionPropertyString("SAMLToken", samlToken);
11// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
12secure.setSessionPropertyBytes("SSLClientCertificate",
13 Files.readAllBytes(Paths.get("****fill in****")));
14// Optional: password to decrypt the private key of the SSL client certificate
15secure.setSessionPropertyString("SSLClientCertificatePassword", "****fill in****");
16// Recommended: Path to server's SSL certificate or its issuer (CA) certificate.
17secure.setSessionPropertyString("SSLServerCertificate", "swisssign-root-ca.cer");
18
19// Begin session using SwissSign SuisseID Signing Service
20if (!secure.beginSession("https://sig.post.ch/sigaas/?SuisseID"))
21 throw new IOException(String.format("Unable to establish connection to SwissSign SuisseID " +
22 "Signing Service. %s (ErrorCode: 0x%08x).", secure.getErrorMessage(),
23 secure.getErrorCode()));
24
25// Add signature and time-stamp
26signature = new Signature();
27
28// Required, name of the signer
29signature.setName(signatureName);
30signature.setTimeStampURL("http://tsa.swisssign.net");
31signature.setReason("Document reviewed!");
32signature.setText1("\t10,44" + signature.getName());
33signature.setFontSize1(15);
34signature.setFontSize2(6);
35signature.setImageFileName("DigitalSignature.jpg");
36signature.setPageNo(1);
37signature.setRect(new float[]{10.0f, 10.0f, 145.0f, 86.0f});
38
39secure.addSignature(signature);
40
41// Sign document
42if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
43 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x).",
44 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
45
46// Cleanup
47secure.close();
48secure.endSession();
49
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: SAML token issued by the SuisseID Identity Provider (IDP)
13PdfSecureSetSessionPropertyString(pSecure, _T("SAMLToken"), szSAMLToken));
14// Required: insert byte array of SSL client certificate in PKCS#12 Format (.p12, .pfx)
15PdfSecureSetSessionPropertyString(pSecure, _T("SSLClientCertificate"), _T("****fill in****"));
16// Optional: password to decrypt the private key of the SSL client certificate
17PdfSecureSetSessionPropertyString(pSecure, _T("SSLClientCertificatePassword"), _T("****fill in****"));
18// Recommended: Path to server's SSL certificate or its issuer (CA) certificate.
19PdfSecureSetSessionPropertyString(pSecure, _T("SSLServerCertificate"), _T("swisssign-root-ca.cer"));
20
21// Begin session using SwissSign SuisseID Signing Service
22if (!PdfSecureBeginSession(pSecure, _T("https://sig.post.ch/sigaas/?SuisseID")))
23{
24 _tprintf(_T("Unable to establish connection to SwissSign Suisse ID Signing Service. %s (ErrorCode: 0x%08x).\n"), PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
25 iReturnValue = 1;
26 goto cleanup;
27}
28
29// Create signature object
30pSignature = PdfSignatureCreateObject();
31
32// Add signature and time-stamp
33// Required, name of the signer
34PdfSignatureSetName(pSignature, szSignatureName);
35PdfSignatureSetTimeStampURL(pSignature, _T("http://tsa.swisssign.net"));
36PdfSignatureSetReason(pSignature, _T("Document reviewed!"));
37PdfSignatureSetText1(pSignature, (_T("\t10,44 %s"), PdfSignatureGetName(pSignature)));
38PdfSignatureSetFontSize1(pSignature, 15);
39PdfSignatureSetFontSize2(pSignature, 6);
40PdfSignatureSetImageFileName(pSignature, _T("DigitalSignature.jpg"));
41PdfSignatureSetPageNo(pSignature, 1);
42PdfSignatureSetRect(pSignature, &rect);
43PdfSecureAddSignature(pSecure, pSignature);
44
45// Sign document
46if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
47{
48 _tprintf(_T("Unable to sign document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
49 iReturnValue = 1;
50 goto cleanup;
51}
52
53// Cleanup
54PdfSecureClose(pSecure);
55PdfSecureEndSession(pSecure);
56
Create visual appearance of a signed 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 // Begin session using 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 signature.Reason = reason;
19 signature.Text1 = "\t10,47 " + signature.Name;
20 signature.Text2 = "\n Reason: " + signature.Reason + "\n Date: " + DateTime.Now;
21 signature.FontSize1 = 10;
22 signature.FontSize2 = 6;
23 signature.ImageFileName = "DigitalSignature.jpg";
24 signature.PageNo = 1;
25 signature.Rect = new PDFRect(10.0f, 10.0f, 145.0f, 86.0f);
26
27 secure.AddSignature(signature);
28
29 // Sign document and imprint visual appearance of signature
30 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
31 throw new Exception(String.Format("Unable to sign document {0}. " +
32 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
33 }
34
35 // Cleanup
36 secure.Close();
37 secure.EndSession();
38}
39
1// Create signature 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 Cryptographic Provider." +
12 "%s (ErrorCode: 0x%08x).", secure.getErrorMessage(), secure.getErrorCode()));
13
14// Create signature object
15signature = new Signature();
16
17signature.setName(certificate);
18signature.setReason(reason);
19signature.setText1("\t10,47 " + signature.getName());
20signature.setText2("\n Reason: " + signature.getReason() + "\n Date: " +
21 new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(Calendar.getInstance().getTime()));
22signature.setFontSize1(10);
23signature.setFontSize2(6);
24signature.setImageFileName("DigitalSignature.jpg");
25signature.setPageNo(1);
26signature.setRect(new float[]{10.0f, 10.0f, 145.0f, 86.0f});
27
28secure.addSignature(signature);
29
30// Sign document and imprint visual appearance of signature
31if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 128, "V2", "V2"))
32 throw new IOException(String.format("Unable to sign document %s. %s (ErrorCode: 0x%08x).",
33 outputPath, secure.getErrorMessage(), secure.getErrorCode()));
34
35// Cleanup
36secure.close();
37secure.endSession();
38
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 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
23// Get current time
24time(&iTime);
25szCurrentTime = localtime(&iTime);
26_tcsftime(szTimeBuffer, 26, _T("%d.%m.%Y %H:%M:%S"), szCurrentTime);
27
28PdfSignatureSetName(pSignature, szCertificate);
29PdfSignatureSetReason(pSignature, szReason);
30_stprintf(szCerBuff, _T("\t10,47 %s"), szCertificate);
31PdfSignatureSetText1(pSignature, szCerBuff);
32_stprintf(szTextBuffer, _T("\n Reason: %s \n Date: %s"), PdfSignatureGetReason(pSignature), szTimeBuffer);
33PdfSignatureSetText2(pSignature, szTextBuffer);
34PdfSignatureSetFontSize1(pSignature, 10);
35PdfSignatureSetFontSize2(pSignature, 6);
36PdfSignatureSetImageFileName(pSignature, "DigitalSignature.jpg");
37PdfSignatureSetPageNo(pSignature, 1);
38PdfSignatureSetRect(pSignature, &rect);
39
40PdfSecureAddSignature(pSecure, pSignature);
41
42// Sign document and imprint visual appearance of signature
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
Time-stamping
Put time-stamp on 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 // Add time-stamp
10 using (Signature timeStamp = new Signature())
11 {
12 timeStamp.TimeStampURL = "http://tsa.swisssign.net";
13 secure.AddTimeStampSignature(timeStamp);
14 }
15
16 // Put time-stamp to document
17 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
18 throw new Exception(String.Format("Unable to add time-stamp to document {0}. " +
19 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
20
21 // Cleanup
22 secure.Close();
23}
24
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// Add time-stamp
10timeStamp = new Signature();
11
12timeStamp.setTimeStampURL("http://tsa.swisssign.net");
13secure.addTimeStampSignature(timeStamp);
14
15// Put time-stamp to document
16if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
17 throw new IOException(String.format("Unable to add time-stamp to document %s. " +
18 "%s (ErrorCode: 0x%08x).", outputPath, secure.getErrorMessage(), secure.getErrorCode()));
19
20// Cleanup
21secure.close();
22
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// Create signature object
13pTimeStamp = PdfSignatureCreateObject();
14
15// Add time-stamp
16PdfSignatureSetTimeStampURL(pTimeStamp, _T("http://tsa.swisssign.net"));
17PdfSecureAddTimeStampSignature(pSecure, pTimeStamp);
18
19// Put time-stamp to document
20if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
21{
22 _tprintf(_T("Unable to add time-stamp to document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
23 iReturnValue = 1;
24 goto cleanup;
25}
26
27// Cleanup
28PdfSecureClose(pSecure);
29
Put time-stamp on 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: 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 time-stamp
28 using (Signature signature = new Signature())
29 {
30 signature.TimeStampURL = "urn:ietf:rfc:3161";
31 secure.AddTimeStampSignature(signature);
32 }
33
34 // Save output document
35 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
36 throw new Exception(String.Format("Unable to add time-stamp to document {0}. " +
37 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
38
39 // Cleanup
40 secure.Close();
41 secure.EndSession();
42}
43
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("****fill in****")));
18// Optional: password to decrypt the private key of the SSL 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 time-stamp
31signature = new Signature();
32
33signature.setTimeStampURL("urn:ietf:rfc:3161");
34secure.addTimeStampSignature(signature);
35
36// Save output document
37if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
38 throw new IOException(String.format("Unable to add time-stamp to document %s. " +
39 "%s (ErrorCode: 0x%08x).", outputPath, secure.getErrorMessage(), secure.getErrorCode()));
40
41// Cleanup
42secure.close();
43
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 establish connection 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
34pTimeStamp = PdfSignatureCreateObject();
35
36// Add time-stamp
37PdfSignatureSetTimeStampURL(pTimeStamp, _T("urn:ietf:rfc:3161"));
38PdfSecureAddTimeStampSignature(pSecure, pTimeStamp);
39
40// Save output document
41if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
42{
43 _tprintf(_T("Unable to add time-stamp to document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
44 iReturnValue = 1;
45 goto cleanup;
46}
47
48// Cleanup
49PdfSecureClose(pSecure);
50PdfSecureEndSession(pSecure);
51
Put time-stamp on 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: 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: 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 time-stamp
30 using (Signature signature = new Signature())
31 {
32 signature.TimeStampURL = "http://tsa.swisssign.net";
33 secure.AddTimeStampSignature(signature);
34 }
35
36 // Save document
37 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
38 throw new Exception(String.Format("Unable to put time-stamp to document {0}. " +
39 "{1} (ErrorCode: 0x{2:x}, Request-ID: {3}).", outputPath, secure.ErrorMessage,
40 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. " +
7 "%s (ErrorCode: 0x%08x).", inputPath, secure.getErrorMessage(), secure.getErrorCode()));
8
9// Required: 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: insert 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 "Service. %s (ErrorCode: 0x%08x).", secure.getErrorMessage(), secure.getErrorCode()));
29
30// Add time-stamp
31signature = new Signature();
32
33signature.setTimeStampURL("http://tsa.swisssign.net");
34secure.addTimeStampSignature(signature);
35
36// Sign document and put time-stamp
37if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
38 throw new IOException(String.format("Unable to put time-stamp to document %s. " +
39 "%s (ErrorCode: 0x%08x, Request-ID: %s).", outputPath, secure.getErrorMessage(),
40 secure.getErrorCode(), requestId));
41
42// Cleanup
43secure.close();
44secure.endSession();
45
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 establish connection 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
34pTimeStamp = PdfSignatureCreateObject();
35
36// Add time-stamp
37PdfSignatureSetTimeStampURL(pTimeStamp, _T("http://tsa.swisssign.net"));
38PdfSecureAddTimeStampSignature(pSecure, pTimeStamp);
39
40// Save document
41if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
42{
43 _tprintf(_T("Unable to put time-stamp to document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
44 iReturnValue = 1;
45 goto cleanup;
46}
47
48// Cleanup
49PdfSecureClose(pSecure);
50PdfSecureEndSession(pSecure);
51
Put time-stamp on 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 // Add time-stamp
10 using (Signature timeStamp = new Signature())
11 {
12 // Begin session using PKCS#11
13 // General: "PathToDll;SlotId;Pin"
14 timeStamp.Provider = "****fill in****";
15 timeStamp.TimeStampURL = "http://tsa.swisssign.net";
16 secure.AddTimeStampSignature(timeStamp);
17 }
18
19 // Put time-stamp to document
20 if (!secure.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption, 0, "", ""))
21 throw new Exception(String.Format("Unable to add time-stamp to document {0}. " +
22 "{1} (ErrorCode: 0x{2:x}).", outputPath, secure.ErrorMessage, secure.ErrorCode));
23
24 // Cleanup
25 secure.Close();
26}
27
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// Add time-stamp
10timeStamp = new Signature();
11
12// Begin session using PKCS#11
13// General: "PathToDll;SlotId;Pin"
14timeStamp.setProvider("*****fill in*****");
15timeStamp.setTimeStampURL("http://tsa.swisssign.net");
16secure.addTimeStampSignature(timeStamp);
17
18// Put time-stamp to document
19if (!secure.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption, 0, "", ""))
20 throw new IOException(String.format("Unable to add time-stamp to document %s. " +
21 "%s (ErrorCode: 0x%08x).", outputPath, secure.getErrorMessage(), secure.getErrorCode()));
22
23// Cleanup
24secure.close();
25
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// Create signature object
13pTimeStamp = PdfSignatureCreateObject();
14
15// Add time-stamp
16// Begin session using PKCS#11
17// General: "PathToDll;SlotId;Pin"
18PdfSignatureSetProvider(pTimeStamp, _T("****fill in****"));
19PdfSignatureSetTimeStampURL(pTimeStamp, _T("http://tsa.swisssign.net"));
20PdfSecureAddSignature(pSecure, pTimeStamp);
21
22// Put time-stamp to document
23if (!PdfSecureSaveAs(pSecure, szOutputPath, _T(""), _T(""), ePermNoEncryption, 0, _T(""), _T("")))
24{
25 _tprintf(_T("Unable to add time-stamp to document %s. %s (ErrorCode: 0x%08x).\n"), szOutputPath, PdfSecureGetErrorMessage(pSecure), PdfSecureGetErrorCode(pSecure));
26 iReturnValue = 1;
27 goto cleanup;
28}
29
30// Cleanup
31PdfSecureClose(pSecure);
32
Put time-stamp on a PDF using Swisscom All-in Signing Service
1// Create secure object
2using (Secure secure = new Secure())
3{
4 // Open input file
5<