[VB6 equivalent: CMS_ReadEnvDataToString]
Dim sbPrivateKey As StringBuilder
Dim strFileIn As String
Dim strDataOut As String
Dim strSize As String
strFileIn = "cms2bobandcarl.p7m"
' First, 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
' Query the size of encrypted content (no need for an output buffer)
strSize = Cms.QueryEnvData(strFileIn, "sizeofEncryptedContent", False)
Console.WriteLine("CMS_QueryEnvData returns " & strSize)
If strSize = "0" Then
GoTo CleanUp
End If
' Pre-dimension string and read in the plaintext
' The final plaintext will always be shorter than the encrypted content.
strDataOut = Cms.ReadEnvDataToString(strFileIn, "", sbPrivateKey.ToString, 0)
Console.WriteLine("CMS_ReadEnvDataToString returns " & strDataOut.Length)
If strDataOut.Length > 0 Then
Console.WriteLine("Plaintext is '" & strDataOut & "'")
End If
CleanUp:
Wipe.String(sbPrivateKey)
See Also:
Cms.ReadEnvDataToString Method