CryptoSys PKI examples VB6 to VB.NET

CMS_MakeDetachedSig

Create a "detached signature" CMS signed-data object from message digest of content.

VB6/VBA

Debug.Print "Testing CMS_MakeDetachedSig ..."
Dim nRet As Long
Dim strEPKFile As String
Dim strCertFile As String
Dim strOutFile As String
Dim strHexDigest As String
Dim strPrivateKey As String

strEPKFile = "AlicePrivRSASign.epk"
strCertFile = "AliceRSASignByCarl.cer"
strOutFile = "DetSignByAlice.bin"
strHexDigest = "406aec085279ba6e16022d9e0629c0229687dd48"

' First, Alice reads her private key into a string
strPrivateKey = rsaReadPrivateKey(strEPKFile, "password")
If Len(strPrivateKey) = 0 Then
    MsgBox "Cannot read private key"
    Exit Sub
End If

' Alice makes a detached signature using
' the hash of the content and her private key
nRet = CMS_MakeDetachedSig(strOutFile, strHexDigest, _
    strCertFile, strPrivateKey, 0)
Debug.Print "CMS_MakeDetachedSig returns " & nRet

Output

Testing CMS_MakeDetachedSig ...
CMS_MakeDetachedSig returns 0

VB.NET

Console.WriteLine("Testing CMS_MakeDetachedSig ...")
Dim nRet As Integer
Dim strEPKFile As String
Dim strCertFile As String
Dim strOutFile As String
Dim strHexDigest As String
Dim strPrivateKey As String

strEPKFile = "AlicePrivRSASign.epk"
strCertFile = "AliceRSASignByCarl.cer"
strOutFile = "DetSignByAlice.bin"
strHexDigest = "406aec085279ba6e16022d9e0629c0229687dd48"

' First, Alice reads her private key into a string
strPrivateKey = Rsa.ReadEncPrivateKey(strEPKFile, "password").ToString()
If Len(strPrivateKey) = 0 Then
    MsgBox("Cannot read private key")
    Exit Sub
End If

' Alice makes a detached signature using
' the hash of the content and her private key
nRet = Cms.MakeDetachedSig(strOutFile, strHexDigest, _
    strCertFile, strPrivateKey, 0)
Console.WriteLine("CMS_MakeDetachedSig returns " & nRet)
[HOME]   [NEXT: CMS_MakeEnvData...]

Copyright © 2010-20 D.I. Management Services Pty Ltd. All rights reserved.