[VB6 equivalent: CMS_GetSigDataDigest]
Dim strCmsFile As String
Dim strHexDigest As String
''Dim nDigAlg As Integer
Dim strData As String
''Dim nDataLen As Integer
Dim strContentDigest As String
''Dim nHashLen As Integer
Dim strDigestAlg As String
strCmsFile = "4.2.bin"
' 1. Get the digest value
''strHexDigest = String(PKI_MAX_HASH_CHARS, " ")
strHexDigest = Cms.GetSigDataDigest(strCmsFile, "", False)
''Console.WriteLine("CMS_GetSigDataDigest returns " & nDigAlg)
If strHexDigest.Length = 0 Then
Exit Sub
End If
Console.WriteLine("Extracted digest is")
Console.WriteLine("[" & strHexDigest & "]")
' 2. Go get the content - in this case it's in the signed-data object
strData = Cms.ReadSigDataToString(strCmsFile, False)
If strData.Length = 0 Then
Exit Sub
End If
Console.WriteLine("Data is [" & strData & "]")
' 3. Compute independently the hash of what we found
' [.NET] We have to query the signed data to find the hash algorithm
strDigestAlg = Cms.QuerySigData(strCmsFile, "digestAlgorithm", False)
Console.WriteLine("digestAlgorithm=" & strDigestAlg)
strContentDigest = Hash.HexFromString(strData, HashAlgorithm.Sha1)
Console.WriteLine("Computed hash of content is")
Console.WriteLine("[" & strContentDigest & "]")
' 4. Can we match this hash digest with
' what we extracted from the signed-data?
If strContentDigest = strHexDigest Then
Console.WriteLine("SUCCESS - digests match!")
Else
Console.WriteLine("FAILS! - no match")
End If
See Also:
Cms.GetSigDataDigest Method