←Select platform

VerifySignature Method

Summary

Verifies Digital Signatures in the Data Set.

Syntax

C#
VB
C++
public bool VerifySignature(  
   Leadtools.Dicom.DicomElement signatureItem 
) 
Public Function VerifySignature( _ 
   ByVal signatureItem As Leadtools.Dicom.DicomElement _ 
) As Boolean 
public: 
bool VerifySignature(  
   Leadtools.Dicom.DicomElement^ signatureItem 
)  

Parameters

signatureItem
The Digital Signatures Sequence Item that corresponds to the Digital Signature to be verified. To verify all the Digital Signatures in the entire Data Set, set this parameter to null.

Return Value

true if The Digital Signature(s) was/were verified successfully; false if the Digital Signature is invalid or at least one of the Digital Signatures is invalid.

Remarks

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

Example

This example will verify a DICOM digital signature and display its details.

C#
VB
Silverlight C#
Silverlight VB
using Leadtools; 
using Leadtools.Dicom; 
 
public void ExamineSignature(DicomDataSet dataset, DicomElement signatureItem) 
{ 
   // Verify the Digital Signature; if pSignatureItem is NULL, the function 
   // will verify all the Digital Signatures that exist in the Data Set 
   bool ret = dataset.VerifySignature(signatureItem); 
   if (ret == true) 
   { 
      if (signatureItem != null) 
      { 
         MessageBox.Show("The Digital Signature was verified.", "Sample"); 
      } 
      else 
      { 
         MessageBox.Show("All Digital Signatures were verified (if there are any).", "Sample"); 
      } 
   } 
   else 
   { 
      if (signatureItem != null) 
      { 
         MessageBox.Show("The Digital Signature is invalid.", "Sample"); 
      } 
      else 
      { 
         MessageBox.Show("At least one Digital Signature is invalid.", "Sample"); 
      } 
   } 
   // The Digital Signature UID 
   StringBuilder msg = new StringBuilder(); 
   msg.Append(dataset.GetSignatureUID(signatureItem)); 
 
   // The Digital Signature DateTime 
   DicomDateTimeValue digitalSignatureDateTime = dataset.GetSignatureDateTime(signatureItem); 
   if (digitalSignatureDateTime.IsEmpty == false) 
   { 
      msg.AppendFormat(" Digital Signature DateTime:{0}/{1}/{2} {3}:{4}:{5}.{6} {7}{8}{9}", 
         digitalSignatureDateTime.Month, 
         digitalSignatureDateTime.Day, 
         digitalSignatureDateTime.Year, 
         digitalSignatureDateTime.Hours, 
         digitalSignatureDateTime.Minutes, 
         digitalSignatureDateTime.Seconds, 
         digitalSignatureDateTime.Fractions, 
         (digitalSignatureDateTime.Offset >= 0) ? '+' : '-', 
         digitalSignatureDateTime.Offset, 
         Environment.NewLine); 
   } 
   string macTransferSyntax = dataset.GetMacTransferSyntax(signatureItem); 
   if (macTransferSyntax != null) 
   { 
      msg.AppendFormat("MAC Calculation Transfer Syntax UID: {0}", macTransferSyntax); 
   } 
 
   string macAlgorithm = dataset.GetMacAlgorithm(signatureItem); 
   if (macAlgorithm != null) 
   { 
      msg.AppendFormat("MAC Algorithm: {0}", macAlgorithm); 
   } 
   // The Data Elements Signed 
   if (dataset.GetSignedElementsCount(signatureItem) > 0) 
   { 
      // We will display only one 
      DicomElement element = dataset.GetSignedElement(signatureItem, 0); 
      msg.AppendFormat(" Data Elements Signed:{0}{1}{1}", element.Tag, Environment.NewLine); 
   } 
   msg.AppendFormat("{0}Do you want to save the Certificate of Signer?", Environment.NewLine); 
   if (MessageBox.Show(msg.ToString(), "Sample", MessageBoxButtons.YesNo) == DialogResult.Yes) 
   { 
      dataset.SaveCertificate(signatureItem, Path.Combine(LEAD_VARS.ImagesDir, "CertOfSigner.cer"), DicomCertificateFormat.Pem); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Dicom 
 
Public Sub ExamineSignature(ByVal dataset As DicomDataSet, ByVal signatureItem As DicomElement) 
   ' Verify the Digital Signature; if pSignatureItem is NULL, the function 
   ' will verify all the Digital Signatures that exist in the Data Set 
   Dim ret As Boolean = dataset.VerifySignature(signatureItem) 
   If ret = True Then 
      If Not signatureItem Is Nothing Then 
         MessageBox.Show("The Digital Signature was verified.", "Sample") 
      Else 
         MessageBox.Show("All Digital Signatures were verified (if there are any).", "Sample") 
      End If 
   Else 
      If Not signatureItem Is Nothing Then 
         MessageBox.Show("The Digital Signature is invalid.", "Sample") 
      Else 
         MessageBox.Show("At least one Digital Signature is invalid.", "Sample") 
      End If 
   End If 
   ' The Digital Signature UID 
   Dim msg As StringBuilder = New StringBuilder() 
   msg.Append(dataset.GetSignatureUID(signatureItem)) 
 
   ' The Digital Signature DateTime 
   Dim digitalSignatureDateTime As DicomDateTimeValue = dataset.GetSignatureDateTime(signatureItem) 
   If digitalSignatureDateTime.IsEmpty = False Then 
      If (digitalSignatureDateTime.Offset >= 0) Then 
         msg.AppendFormat(" Digital Signature DateTime:{0}/{1}/{3} {4}:{5}:{6}.{7} {8}{9}", digitalSignatureDateTime.Month, digitalSignatureDateTime.Day, digitalSignatureDateTime.Year, digitalSignatureDateTime.Hours, 
               digitalSignatureDateTime.Minutes, digitalSignatureDateTime.Seconds, digitalSignatureDateTime.Fractions, "+"c, digitalSignatureDateTime.Offset, Environment.NewLine) 
      Else 
         msg.AppendFormat(" Digital Signature DateTime:{0}/{1}/{3} {4}:{5}:{6}.{7} {8}{9}", digitalSignatureDateTime.Month, digitalSignatureDateTime.Day, digitalSignatureDateTime.Year, digitalSignatureDateTime.Hours, 
               digitalSignatureDateTime.Minutes, digitalSignatureDateTime.Seconds, digitalSignatureDateTime.Fractions, "-"c, digitalSignatureDateTime.Offset, Environment.NewLine) 
      End If 
   End If 
   Dim macTransferSyntax As String = dataset.GetMacTransferSyntax(signatureItem) 
   If Not macTransferSyntax Is Nothing Then 
      msg.AppendFormat("MAC Calculation Transfer Syntax UID: {0}", macTransferSyntax) 
   End If 
 
   Dim macAlgorithm As String = dataset.GetMacAlgorithm(signatureItem) 
   If Not macAlgorithm Is Nothing Then 
      msg.AppendFormat("MAC Algorithm: {0}", macAlgorithm) 
   End If 
   ' The Data Elements Signed 
   If dataset.GetSignedElementsCount(signatureItem) > 0 Then 
      ' We will display only one 
      Dim element As DicomElement = dataset.GetSignedElement(signatureItem, 0) 
      msg.AppendFormat(" Data Elements Signed:{0}{1}{1}", element.Tag, Environment.NewLine) 
   End If 
   msg.AppendFormat("{0}Do you want to save the Certificate of Signer?", Environment.NewLine) 
   If MessageBox.Show(msg.ToString(), "Sample", MessageBoxButtons.YesNo) = DialogResult.Yes Then 
      dataset.SaveCertificate(signatureItem, Path.Combine(LEAD_VARS.ImagesDir, "CertOfSigner.cer"), DicomCertificateFormat.Pem) 
   End If 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Dicom; 
using Leadtools.Examples; 
 
//public void ExamineSignature(DicomDataSet dataset, DicomElement signatureItem, Stream outputStream) 
//{ 
//   // Verify the Digital Signature; if pSignatureItem is NULL, the function 
//   // will verify all the Digital Signatures that exist in the Data Set 
//   bool ret = dataset.VerifySignature(signatureItem); 
//   if (ret == true) 
//   { 
//      if (signatureItem != null) 
//      { 
//         Debug.WriteLine("The Digital Signature was verified.", "Sample"); 
//      } 
//      else 
//      { 
//         Debug.WriteLine("All Digital Signatures were verified (if there are any).", "Sample"); 
//      } 
//   } 
//   else 
//   { 
//      if (signatureItem != null) 
//      { 
//         Debug.WriteLine("The Digital Signature is invalid.", "Sample"); 
//      } 
//      else 
//      { 
//         Debug.WriteLine("At least one Digital Signature is invalid.", "Sample"); 
//      } 
//   } 
//   // The Digital Signature UID 
//   StringBuilder msg = new StringBuilder(); 
//   msg.Append(dataset.GetSignatureUID(signatureItem)); 
 
//   // The Digital Signature DateTime 
//   DicomDateTimeValue digitalSignatureDateTime = dataset.GetSignatureDateTime(signatureItem); 
//   if (digitalSignatureDateTime.IsEmpty == false) 
//   { 
//      msg.AppendFormat(" Digital Signature DateTime:{0}/{1}/{3} {4}:{5}:{6}.{7} {8}{9}{10}", 
//         digitalSignatureDateTime.Month, 
//         digitalSignatureDateTime.Day, 
//         digitalSignatureDateTime.Year, 
//         digitalSignatureDateTime.Hours, 
//         digitalSignatureDateTime.Minutes, 
//         digitalSignatureDateTime.Seconds, 
//         digitalSignatureDateTime.Fractions, 
//         (digitalSignatureDateTime.Offset >= 0) ? '+' : '-', 
//         digitalSignatureDateTime.Offset, 
//         Environment.NewLine); 
//   } 
//   string macTransferSyntax = dataset.GetMacTransferSyntax(signatureItem); 
//   if (macTransferSyntax != null) 
//   { 
//      msg.AppendFormat("MAC Calculation Transfer Syntax UID: {0}", macTransferSyntax); 
//   } 
 
//   string macAlgorithm = dataset.GetMacAlgorithm(signatureItem); 
//   if (macAlgorithm != null) 
//   { 
//      msg.AppendFormat("MAC Algorithm: {0}", macAlgorithm); 
//   } 
//   // The Data Elements Signed 
//   if (dataset.GetSignedElementsCount(signatureItem) > 0) 
//   { 
//      // We will display only one 
//      DicomElement element = dataset.GetSignedElement(signatureItem, 0); 
//      msg.AppendFormat(" Data Elements Signed:{0}{1}{1}", element.Tag, Environment.NewLine); 
//   } 
//   msg.AppendFormat("{0}Do you want to save the Certificate of Signer?", Environment.NewLine); 
//   Debug.WriteLine(msg.ToString()) 
//   dataset.SaveCertificate(signatureItem, outputStream, DicomCertificateFormat.Pem); 
//} 
Imports Leadtools 
Imports Leadtools.Dicom 
 
'public void ExamineSignature(DicomDataSet dataset, DicomElement signatureItem, Stream outputStream) 
'{ 
'   // Verify the Digital Signature; if pSignatureItem is NULL, the function 
'   // will verify all the Digital Signatures that exist in the Data Set 
'   bool ret = dataset.VerifySignature(signatureItem); 
'   if (ret == true) 
'   { 
'      if (signatureItem != null) 
'      { 
'         Debug.WriteLine("The Digital Signature was verified.", "Sample"); 
'      } 
'      else 
'      { 
'         Debug.WriteLine("All Digital Signatures were verified (if there are any).", "Sample"); 
'      } 
'   } 
'   else 
'   { 
'      if (signatureItem != null) 
'      { 
'         Debug.WriteLine("The Digital Signature is invalid.", "Sample"); 
'      } 
'      else 
'      { 
'         Debug.WriteLine("At least one Digital Signature is invalid.", "Sample"); 
'      } 
'   } 
'   // The Digital Signature UID 
'   StringBuilder msg = new StringBuilder(); 
'   msg.Append(dataset.GetSignatureUID(signatureItem)); 
 
'   // The Digital Signature DateTime 
'   DicomDateTimeValue digitalSignatureDateTime = dataset.GetSignatureDateTime(signatureItem); 
'   if (digitalSignatureDateTime.IsEmpty == false) 
'   { 
'      msg.AppendFormat(" Digital Signature DateTime:{0}/{1}/{3} {4}:{5}:{6}.{7} {8}{9}{10}", 
'         digitalSignatureDateTime.Month, 
'         digitalSignatureDateTime.Day, 
'         digitalSignatureDateTime.Year, 
'         digitalSignatureDateTime.Hours, 
'         digitalSignatureDateTime.Minutes, 
'         digitalSignatureDateTime.Seconds, 
'         digitalSignatureDateTime.Fractions, 
'         (digitalSignatureDateTime.Offset >= 0) ? '+' : '-', 
'         digitalSignatureDateTime.Offset, 
'         Environment.NewLine); 
'   } 
'   string macTransferSyntax = dataset.GetMacTransferSyntax(signatureItem); 
'   if (macTransferSyntax != null) 
'   { 
'      msg.AppendFormat("MAC Calculation Transfer Syntax UID: {0}", macTransferSyntax); 
'   } 
 
'   string macAlgorithm = dataset.GetMacAlgorithm(signatureItem); 
'   if (macAlgorithm != null) 
'   { 
'      msg.AppendFormat("MAC Algorithm: {0}", macAlgorithm); 
'   } 
'   // The Data Elements Signed 
'   if (dataset.GetSignedElementsCount(signatureItem) > 0) 
'   { 
'      // We will display only one 
'      DicomElement element = dataset.GetSignedElement(signatureItem, 0); 
'      msg.AppendFormat(" Data Elements Signed:{0}{1}{1}", element.Tag, Environment.NewLine); 
'   } 
'   msg.AppendFormat("{0}Do you want to save the Certificate of Signer?", Environment.NewLine); 
'   Debug.WriteLine(msg.ToString()) 
'   dataset.SaveCertificate(signatureItem, outputStream, DicomCertificateFormat.Pem); 
'} 

Requirements

Target Platforms

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Leadtools.Dicom Assembly
Click or drag to resize