Applying Digital Signatures through code

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
Kiefer
Posts: 25
Joined: Mon Sep 30 2002

Applying Digital Signatures through code

Post by Kiefer » Sun Feb 27 2005

I see the calls to do this in the new 2.5 Pro API, but how do I specify which digital signature I want to use?

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Mon Feb 28 2005

Hello,

The first parameter in the DigitalSignature() method is the signer name, this means the digital signature you want to use.

Hope this helps.

Kiefer
Posts: 25
Joined: Mon Sep 30 2002

Selecting Digital Signature

Post by Kiefer » Mon Feb 28 2005

OK, thanks. What are acceptable values for this? PVK files? How do I select a digital signature from my signature store the way (I assume) the selector button on your full version does (I don't have this, so I am guessing as to its functionality based on the way Acrobat operates...)?

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Tue Mar 01 2005

Hello,

Each digital signature used or created in Adobe has a name. You need to use the digital signature name to sign the file.

Hope this helps.

Kiefer
Posts: 25
Joined: Mon Sep 30 2002

Displaying "Select Signature" dialog

Post by Kiefer » Thu Mar 03 2005

OK, but is there an API call that will allow me to show the "Select Signature" dialog box, the way you do with your selection button on the driver?

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Fri Mar 04 2005

Hello David,

The API that we use is CryptUIDlgSelectCertificateFromStore.

This API should be called dynamically because some systems might be missing the right version of CryptoAPI.

Example:

Code: Select all

typedef PCCERT_CONTEXT WINAPI 
CryptUIDlgSelectCertificateFromStore_T(
            IN HCERTSTORE hCertStore,
            IN OPTIONAL HWND hwnd,
            IN OPTIONAL LPCWSTR pwszTitle,
            IN OPTIONAL LPCWSTR pwszDisplayString,
            IN DWORD dwDontUseColumn,
            IN DWORD dwFlags,
            IN VOID *pvReserved);

 HCERTSTORE m_hCertStore = NULL;
 PCCERT_CONTEXT m_pCertContext = NULL;
 LPWSTR pszStoreName = L"MY";
 
 CryptUIDlgSelectCertificateFromStore_T* CryptUIDlgSelectCertificateFromStore_Proc = NULL;

 HMODULE m_shLib = ::LoadLibrary ("CryptUI.dll");
 
 if(!m_shLib)
 {
  // generate an error;
 }
 
 CryptUIDlgSelectCertificateFromStore_Proc = 
  (CryptUIDlgSelectCertificateFromStore_T*)GetProcAddress (m_shLib , "CryptUIDlgSelectCertificateFromStore"); 
 
 if(CryptUIDlgSelectCertificateFromStore_Proc == NULL)
 {
  // generate an error
 }
 

 if( (m_hCertStore = CertOpenStore(CERT_STORE_PROV_SYSTEM,
            0,
            NULL,
            CERT_SYSTEM_STORE_CURRENT_USER,
            pszStoreName)) == NULL)       
 {
  // generate an error
 }
 
 if(!(m_pCertContext = CryptUIDlgSelectCertificateFromStore_Proc 
       (m_hCertStore, NULL, NULL, NULL, CRYPTUI_SELECT_LOCATION_COLUMN,0, NULL)))
 {
  // generate an error
 }
 
 char m_signerName[MAX_NAME_LEN]; //This is the signer name that we are looking for

 if((CertGetNameString(m_pCertContext, CERT_NAME_FRIENDLY_DISPLAY_TYPE,0, NULL, m_signerName, MAX_NAME_LEN) <= 1)
  )
 {
  // generate an error
 }

 if (m_hCertStore)
  CertCloseStore(m_hCertStore,0);
 if(m_shLib) ::FreeLibrary (m_shLib );
 return;

Kiefer
Posts: 25
Joined: Mon Sep 30 2002

Post by Kiefer » Fri Mar 04 2005

SWEET! Thanks very much.

Post Reply