Examining a Digital Signature Example for C++ 6.0 and later
void ExamineSignature(ILEADDicomDSPtr& spDicomDS, long hSignatureItem)
{
char szMsg[1024] = "";
spDicomDS->SetCurrentElement (hSignatureItem);
// Verify the Digital Signature; if hSignatureItem is 0, the method will
// verify all the Digital Signatures that exist in the Data Set
short nRet = spDicomDS->VerifySignature(0);
switch (nRet)
{
case DICOM_SUCCESS:
if (hSignatureItem)
{
::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 (hSignatureItem)
{
::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: %hd].", nRet);
::MessageBox(NULL, szMsg, "Sample", MB_OK);
return;
}
// The Digital Signature UID
if (spDicomDS->GetSignatureUID() == DICOM_SUCCESS)
{
if (spDicomDS->StringValueCount> 0)
{
wsprintf(szMsg, "Digital Signature UID: %s\n",
spDicomDS->StringValues[0].operator char *());
}
}
// The Digital Signature DateTime
if (spDicomDS->GetSignatureDateTime() == DICOM_SUCCESS)
{
if (spDicomDS->DateTimeValueCount > 0)
{
IDATETIMEVALUEItemPtr spSignatureDateTime = spDicomDS->DateTimeValues [0];
wsprintf(szMsg, "%sDigital Signature DateTime: "
"%02hd/%02hd/%04hd %02hd:%02hd:%02hd.%06ld %c%04ld\n",
szMsg,
spSignatureDateTime->Month,
spSignatureDateTime->Day,
spSignatureDateTime->Year,
spSignatureDateTime->Hours,
spSignatureDateTime->Minutes,
spSignatureDateTime->Seconds,
spSignatureDateTime->Fractions,
(spSignatureDateTime->Offset >= 0) ? '+' : '-',
spSignatureDateTime->Offset);
}
}
// The MAC Calculation Transfer Syntax UID
if (spDicomDS->GetMacTransferSyntax () == DICOM_SUCCESS)
{
if (spDicomDS->StringValueCount > 0)
{
wsprintf(szMsg, "%sMAC Calculation Transfer Syntax UID: %s\n",
szMsg,
spDicomDS->StringValues[0].operator char *());
}
}
// The MAC Algorithm
if (spDicomDS->GetMacAlgorithm() == DICOM_SUCCESS)
{
if (spDicomDS->StringValueCount > 0)
{
wsprintf(szMsg, "%sMAC Algorithm: %s\n",
szMsg,
spDicomDS->StringValues[0].operator char *());
}
}
// The Data Elements Signed
if (spDicomDS->GetSignedElementsCount() > 0)
{
lstrcat(szMsg, "Data Elements Signed: ");
// We will display only one
if (spDicomDS->MoveSignedElement(0) == DICOM_SUCCESS)
{
long lTag = spDicomDS->GetCurrentElement()->Tag;
wsprintf(szMsg, "%s(%04X,%04X), ...",
szMsg,
lTag >> 16,
lTag & 0xFFFF);
spDicomDS->SetCurrentElement (hSignatureItem);
}
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
spDicomDS->SaveCertificate("C:\\CertOfSigner.cer",
DICOM_CERTIFICATE_FORMAT_PEM);
}
}