Create a CMS signed-data object using sender's private key.
VB6/VBA
Debug.Print "Testing CMS_MakeSigData ..." Dim strPriFile As String Dim strPrivateKey As String Dim nIntKeyLen As Long Dim nRet As Long Dim strInputFile As String Dim strOutputFile As String Dim strCertFile As String strPriFile = "AlicePrivRSASign.pri" strCertFile = "AliceRSASignByCarl.cer" strInputFile = "excontent.txt" strOutputFile = "BasicSignByAlice.bin" ' First we need to read in the private key string ' NB: This version is not encrypted nIntKeyLen = RSA_ReadPrivateKeyInfo("", 0, strPriFile, 0) Debug.Print "nIntKeyLen = " & nIntKeyLen If nIntKeyLen <= 0 Then Debug.Print pkiGetLastError() MsgBox "Unable to retrieve private key" Exit Sub End If ' Pre-dimension the string to receive data strPrivateKey = String(nIntKeyLen, " ") ' Read in the Private Key nRet = RSA_ReadPrivateKeyInfo(strPrivateKey, nIntKeyLen, strPriFile, 0) Debug.Print "Key size=" & RSA_KeyBits(strPrivateKey) & " bits" ' Now we can sign our message nRet = CMS_MakeSigData(strOutputFile, strInputFile, strCertFile, strPrivateKey, 0) Debug.Print "CMS_MakeSigData returns " & nRet
Output
Testing CMS_MakeSigData ... nIntKeyLen = 848 Key size=1024 bits CMS_MakeSigData returns 0
VB.NET
Console.WriteLine("Testing CMS_MakeSigData ...")
Dim strPriFile As String
Dim sbPrivateKey As StringBuilder
''Dim nIntKeyLen As Integer
Dim nRet As Integer
Dim strInputFile As String
Dim strOutputFile As String
Dim strCertFile As String
strPriFile = "AlicePrivRSASign.pri"
strCertFile = "AliceRSASignByCarl.cer"
strInputFile = "excontent.txt"
strOutputFile = "BasicSignByAlice.bin"
' First we need to read in the private key string
' NB: This version is not encrypted
sbPrivateKey = Rsa.ReadPrivateKeyInfo(strPriFile)
Console.WriteLine("nIntKeyLen = " & sbPrivateKey.Length)
If sbPrivateKey.Length = 0 Then
Console.WriteLine(General.LastError())
Console.WriteLine("Unable to retrieve private key")
Exit Sub
End If
Console.WriteLine("Key size=" & Rsa.KeyBits(sbPrivateKey.ToString()) & " bits")
' Now we can sign our message
nRet = Cms.MakeSigData(strOutputFile, strInputFile, strCertFile, sbPrivateKey.ToString, 0)
Console.WriteLine("CMS_MakeSigData returns " & nRet)
[Contents]