Public Sub ExamineSignature(ByVal dataset As DicomDataSet, ByVal signatureItem As DicomElement)
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
Dim msg As StringBuilder = New StringBuilder()
msg.Append(dataset.GetSignatureUID(signatureItem))
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}{10}", 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}{10}", 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
If dataset.GetSignedElementsCount(signatureItem) > 0 Then
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, LeadtoolsExamples.Common.ImagesPath.Path + "CertOfSigner.cer", DicomCertificateFormat.Pem)
End If
End Sub |