LDicomDS::VerifySignature

#include "ltdic.h"

L_UINT16 LDicomDS::VerifySignature(pSignatureItem, uReserved = 0)

pDICOMELEMENT pSignatureItem;

/* pointer to a Digital Signatures Sequence Item */

L_UINT16 uReserved;

/* reserved */

Verifies Digital Signatures in the Data Set.

Parameter

Description

pSignatureItem

Pointer to a DICOMELEMENT structure that specifies the Digital Signatures Sequence Item which corresponds to the Digital Signature to be verified. To verify all the Digital Signatures in the entire Data Set, set this parameter to NULL.

uReserved

Reserved for future use. This must be set to 0.

Returns

DICOM_SUCCESS

The Digital Signature(s) was/were verified successfully.

DICOM_ERROR_INVALID_SIGNATURE

The Digital Signature is invalid or at least one of the Digital Signatures is invalid.

(Otherwise)

An error occurred. Refer to Return Codes.

Comments

To verify all the Digital Signatures in the entire Data Set, set the pSignatureItem parameter to NULL. If at least one of these Digital Signatures is invalid, the function returns DICOM_ERROR_INVALID_SIGNATURE and does not examine the remaining Digital Signatures, if there are any.

Required DLLs and Libraries

LTDIC

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

LDicomDS::GetSignature, LDicomDS::FindSignature, LDicomDS::DeleteSignature, LDicomDS::CreateSignature, Class Members

Topics:

Working with Digital Signatures

Example

L_VOID ExamineSignature(LDicomDS& DataSet, pDICOMELEMENT pSignatureItem) 
{
   L_CHAR szMsg[1024] = "";

   // Verify the Digital Signature; if pSignatureItem is NULL, the function
   // will verify all the Digital Signatures that exist in the Data Set
   L_UINT16 uRet = DataSet.VerifySignature(pSignatureItem); 
   switch (uRet) 
   {
   case DICOM_SUCCESS: 
      if (pSignatureItem) 
      {
         ::MessageBox(NULL, 
                      "The Digital Signature was verified.", 
                      "Sample",
                      MB_OK); 
      }
      else
      {
         ::MessageBox(NULL, 
                      "All Digital Signatures were verified "
                      "(if there are any).", 
                      "Sample",
                      MB_OK); 
         return; 
      }
      break; 

   case DICOM_ERROR_INVALID_SIGNATURE: 
      if (pSignatureItem) 
      {
         ::MessageBox(NULL, 
                      "The Digital Signature is invalid.", 
                      "Sample",
                      MB_OK); 
      }
      else
      {
         ::MessageBox(NULL, 
                      "At least one Digital Signature is invalid.", 
                      "Sample",
                      MB_OK); 
      }
      return; 

   default: 
      wsprintf(szMsg, "An error occurred [Error: %hu].", uRet); 
      ::MessageBox(NULL, szMsg, "Sample", MB_OK); 
      return; 
   }

   // The Digital Signature UID
   L_CHAR* pszSignatureUID; 
   pszSignatureUID = DataSet.GetSignatureUID(pSignatureItem); 
   if (pszSignatureUID) 
   {
      wsprintf(szMsg, "Digital Signature UID: %s\n", pszSignatureUID); 
   }

   // The Digital Signature DateTime
   pVALUEDATETIME pSignatureDateTime; 
   pSignatureDateTime = DataSet.GetSignatureDateTime(pSignatureItem); 
   if (pSignatureDateTime) 
   {
      wsprintf(szMsg, "%sDigital Signature DateTime: "
               "%02hu/%02hu/%04hu %02hu:%02hu:%02hu.%06lu %c%04li\n",
               szMsg, 
               pSignatureDateTime->nMonth, 
               pSignatureDateTime->nDay, 
               pSignatureDateTime->nYear, 
               pSignatureDateTime->nHours, 
               pSignatureDateTime->nMinutes, 
               pSignatureDateTime->nSeconds, 
               pSignatureDateTime->nFractions, 
               (pSignatureDateTime->nOffset >= 0) ? '+' : '-', 
               pSignatureDateTime->nOffset); 
   }

   // The MAC Calculation Transfer Syntax UID
   L_CHAR* pszMacTransferSyntax; 
   pszMacTransferSyntax = DataSet.GetMacTransferSyntax(pSignatureItem); 
   if (pszMacTransferSyntax) 
   {
      wsprintf(szMsg, "%sMAC Calculation Transfer Syntax UID: %s\n",
               szMsg, 
               pszMacTransferSyntax); 
   }

   // The MAC Algorithm
   L_CHAR* pszMacAlgorithm; 
   pszMacAlgorithm = DataSet.GetMacAlgorithm(pSignatureItem); 
   if (pszMacAlgorithm) 
   {
      wsprintf(szMsg, "%sMAC Algorithm: %s\n",
               szMsg, 
               pszMacAlgorithm); 
   }

   // The Data Elements Signed
   if (DataSet.GetSignedElementsCount(pSignatureItem) > 0) 
   {
      lstrcat(szMsg, "Data Elements Signed: ");

      // We will display only one
      pDICOMELEMENT pSignedElement; 
      pSignedElement = DataSet.GetSignedElement(pSignatureItem, 0); 
      if (pSignedElement) 
      {
         wsprintf(szMsg, "%s(%04X,%04X), ...", 
                  szMsg, 
                  GETGROUP(pSignedElement->nTag), 
                  GETELEMENT(pSignedElement->nTag)); 
      }

      lstrcat(szMsg, "\n");
   }

   lstrcat(szMsg, "\nDo you want to save the Certificate of Signer?"); 

   // Display the information we have about the Digital Signature
   if (::MessageBox(NULL, szMsg, "Sample", MB_YESNO) == IDYES) 
   {
      // Save the Certificate of Signer
      DataSet.SaveCertificate(pSignatureItem, "C:\\CertOfSigner.cer");
   }
}