Reads and decrypts a CMS enveloped-data object using recipient's private key.
VB6/VBA
Debug.Print "Testing CMS_ReadEnvData ..." Dim nRet As Long Dim strFileIn As String Dim strFileOut As String Dim strPrivateKey As String ' Bob reads his private key into a string strPrivateKey = rsaReadPrivateKey("BobPrivRSAEncrypt.epk", "password") If Len(strPrivateKey) = 0 Then MsgBox "Cannot read private key" Exit Sub End If ' Decrypt the input file, send plaintext to new output file strFileIn = "cmsalice2bob.p7m" strFileOut = "fromalice.txt" nRet = CMS_ReadEnvData(strFileOut, strFileIn, "", strPrivateKey, 0) Debug.Print "CMS_ReadEnvData returns " & nRet ' Clean up WIPE_String strPrivateKey, Len(strPrivateKey) strPrivateKey = ""
Output
Testing CMS_ReadEnvData ... CMS_ReadEnvData returns 0
VB.NET
Console.WriteLine("Testing CMS_ReadEnvData ...")
Dim nRet As Integer
Dim strFileIn As String
Dim strFileOut As String
Dim sbPrivateKey As StringBuilder
' Bob reads his private key into a string
sbPrivateKey = Rsa.ReadEncPrivateKey("BobPrivRSAEncrypt.epk", "password")
If sbPrivateKey.Length = 0 Then
Console.WriteLine("Cannot read private key")
Exit Sub
End If
' Decrypt the input file, send plaintext to new output file
strFileIn = "cmsalice2bob.p7m"
strFileOut = "fromalice.txt"
nRet = Cms.ReadEnvDataToFile(strFileOut, strFileIn, "", sbPrivateKey.ToString(), 0)
Console.WriteLine("CMS_ReadEnvData returns " & nRet)
' Clean up
Wipe.String(sbPrivateKey)
[Contents]