Source code for the AS2 Client VB .NET example program posted at EDIINT AS2.  A detailed explanation of the algorithm can be read at "Creating an AS2 Client in Stages".

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click

        Me.Cursor = Cursors.WaitCursor

        Dim nMdnResult As Integer = 0
        Dim sErrorMsg As String = ""

        txtNotification.Text = ""


            ' Get internet mail document object
            Dim oMailDocument As mailDocument = oEdiDoc.GetMailDocument

            'Setting so that syntax for the field "Disposition-Notification-To" is not validated, but treated as a text field
            oMailDocument.AddDefinedHeader("Disposition-Notification-To", MailMessageHeaderTypeConstants.HeaderType_FieldText, RequirementTypeConstants.Requirement_Optional)

            Dim oSubjMsg As mailMessage = oMailDocument.GetMessageContent
            Label1.Text = "importing EDI..."
            ' For speed, import the EDI file instead of processing.
            If oSubjMsg.Import(sPath & cmbFile.Text) <> 1 Then

                MessageBox.Show("Failed to load document")


                'specify content type of mesage
                oSubjMsg.HeaderFieldValue("Content-Type") = txtContentType.Text

                Dim oSecurity As ediSecurity
                ' Configure the security of this message.
                oSecurity = oSubjMsg.GetSecurity

                ' Specify the type of encryption and signing algorithm to use
                oSecurity.EncryptionAlgorithm = sEncryptAlgorithm
                oSecurity.AssuranceAlgorithm = sSigningHash

                ' Recipient's certificate to encrypt message.
                oSecurity.SetCertSubjectNameByLocation(sRecCertSubjName, sRecCertStoreLocation, sRecCertStoreName, sRecServiceProvider)

                ' Sender's certificate to sign message.
                oSecurity.SetCertSignerNameByLocation(sSignCertSubjName, sSignCertStoreLocation, sSignCertStoreName, sSignServiceProvider)

                If ckSendEncrypted.Checked = True Then
                    oSecurity.EnableEncryption = True
                    oSecurity.EnableEncryption = False
                End If

                If ckSendSigned.Checked = True Then
                    oSecurity.EnableAssurance = True
                    oSecurity.EnableAssurance = False
                End If

                If ckCompression.Checked = True Then
                    oSecurity.EnableCompression = True
                    oSecurity.EnableCompression = False
                End If

                'This is how the content of the file looks like before it is prepared with all
                'the security configuration.  This is also how your trading partner would see
                'the content of your file after he decrypts the AS2 message you send him.
                '(This is the garbled section of the "Sent_SampleEdiX12_850.x12)"
                oMailDocument.Save(sPath & "Output\MessageContent.txt")

                ' Calculate the MIC value from the original message.
                'Dim sSubjMicValue As String

                If oSecurity.EnableEncryption Or oSecurity.EnableAssurance Then

                    'RFC4130: For any signed messages, the MIC to be returned is calculated
                    'on the RFC1767/RFC3023 MIME header and content.
                    'Canonicalization on the MIME headers MUST be performed before
                    'the MIC is calculated, since the sender requesting the signed
                    'receipt was also REQUIRED to canonicalize.

                    'RFC4130: For encrypted, unsigned messages, the MIC to be returned is
                    'calculated on the decrypted RFC 1767/RFC3023 MIME header and
                    'content.  The content after decryption MUST be canonicalized
                    'before the MIC is calculated.

                    sSubjMicValue = oSubjMsg.GenerateDigest(MailMessagePartTypeConstants.Message_All, EncodingMechanismTypeConstants.EncodeType_Base64)

                    'RFC4130: For unsigned, unencrypted messages, the MIC MUST be calculated
                    'over the message contents without the MIME or any other RFC
                    '2822 headers, since these are sometimes altered or reordered by
                    'Mail Transport Agents (MTAs).
                    sSubjMicValue = oSubjMsg.GenerateDigest(MailMessagePartTypeConstants.Message_Body, EncodingMechanismTypeConstants.EncodeType_Base64)
                End If

                txtMIC.Text = sSubjMicValue

                ' Prepare the message with the imported EDI file so that the security configurations
                '   can be applied.
                If oSubjMsg.Prepare <> 1 Then

                    MessageBox.Show("Failed to prepare Message")


                    If ckBase64.Checked = True Then
                        oMailDocument.Save(sPath & "Output\After_PrepBeforeBase64.txt")
                        oSubjMsg.HeaderFieldValue("Content-Transfer-Encoding") = "base64"
                    End If

                    ' Put globally unique ID as Message-ID.
                    oSubjMsg.HeaderFieldValue("Message-ID") = ""  'txtMessageID.Text

                    ' Put AS2 version.
                    oSubjMsg.HeaderFieldValue("AS2-Version") = "1.0"
                    ' Put AS2-To header value.
                    oSubjMsg.HeaderFieldValue("AS2-To") = txtAs2To.Text
                    ' Put AS2-From header value.
                    oSubjMsg.HeaderFieldValue("AS2-From") = txtAS2From.Text

                    If ckAsynchronous.Checked = True Then
                        ' For asynchronous, must set a syntactically correct URI at 'Receipt-delivery-option'.
                        oSubjMsg.HeaderFieldValue("Receipt-delivery-option") = txtReceiptDeliveryOption.Text
                    End If

                    If ckReceiveMdn.Checked = True Then
                        ' Request Acknowledgment by adding "Disposition-Notification-To" header.
                        '  Value must be present but holds no meaning in an AS2 environment.
                        oSubjMsg.HeaderFieldValue("Disposition-Notification-To") = txtDispositionNotificationTo.Text

                        If ckReceiveSigned.Checked = True Then
                            ' Request the MDN to be signed.
                            Dim sDnOpts As String
                            sDnOpts = "signed-receipt-protocol=optional,pkcs7-signature;"
                            sDnOpts = sDnOpts & "signed-receipt-micalg=optional,sha1"
                            oSubjMsg.HeaderFieldValue("Disposition-Notification-Options") = sDnOpts
                        End If
                    End If  'ckReceiveMdn.Value = 1

                    ' Save the document before sending.
                    If oMailDocument.Save(sPath & "Output\Sent_File.txt") <> 1 Then

                        MessageBox.Show("Failed to save message")


                        ' Get the transports object for internet mail documents.
                        Dim oTransports As ediTransports = oMailDocument.GetTransports

                        ' Create a transport token, and set the information of the
                        '   HTTP server where to send the file.
                        Dim oTransport As ediTransport = oTransports.CreateTransport
                        ' *** Note that FREDI requires the forward-slash (/) at the end of the HTTP URI for posting
                        ' e.g
                        oTransport.InternetUrl = cmbUrl.Text
                        oTransport.TimeOut = 7200

                        ' Configure the ISAPI information in the HTTP config object.  These settings are specific
                        '   only to the FREDI ISAPI extension and the ActiveX components that it drives.

                        Dim oHttpCfg As ediHttpCfg = oTransport.GetHttpCfg
                        oHttpCfg.SendVerb = "POST"

                        ' If there are no errors received from the HTTP server and data is
                        '   received, we want that data to be processed.
                        oHttpCfg.EnableProcessResponse = True

                        ' Specify the file name to save the received raw data from the server.
                        '   The raw data is saved only if the transfer is successful.
                        oHttpCfg.ResponseOutput = sPath & "output\Receive.Mime.Txt"

                        ' Send the file to the server. If it's a synchronous connection, then
                        '   wait for incoming data from the server.
                        '   Execution on the server side may take several minutes
                        '   which means that the Send() statement will be blocked for the
                        '   same period until processing the file has been completed and
                        '   then received, or if an error has occurred.
                        Label1.Text = "sending..."


                        If ckReceiveMdn.Checked = True And ckAsynchronous.Checked = False Then 'synchronous

                            ' If the send is successful, we expect an MDN to be received from the server
                            '   during the Send call.  This is because this session is a synchronous session
                            '   and the MDN must be received in the same HTTP connection that the message
                            '   itself was sent.  Since the MDN is already received, get the MDN message and save
                            '   the MDN to an external file.
                            Dim oMDN As mailMessage = oMailDocument.GetMDN
                            txtNotification.Text = oMDN.GetMsgString

                            Dim oMdnMsgs As mailMessages = oMDN.GetMessages
                            'Reading the MDN
                            For ii As Integer = 1 To oMdnMsgs.Count

                                Dim oMdnMsg As mailMessage = oMdnMsgs.GetMessageContent(ii)

                                Dim oContentType As mailContentType

                                mailContentType.Set(oContentType, oMdnMsg.GetContentType)    'oContentType = oMdnMsg.GetContentType

                                If oContentType.MediaType = "message" And oContentType.SubType = "disposition-notification" Then

                                    Dim oSubMessages As mailMessages = oMdnMsg.GetMessages
                                    Dim oDisposition As mailMessage = oSubMessages.GetMessageContent(1)

                                    If Not oDisposition Is Nothing Then

                                        Dim oHeaders As mailHeaders = oDisposition.GetHeaders
                                        Dim oHeader As mailHeader = Nothing
                                        Dim sHeaders As String = ""
                                        Dim i As Integer

                                        sErrorMsg = ""

                                        For i = 1 To oHeaders.Count
                                            mailHeader.Set(oHeader, oHeaders.GetHeaderByIndex(i))      'oHeader = oHeaders.GetHeaderByIndex(i)
                                            sHeaders = sHeaders & oHeader.Name & " : " & oHeader.Value & vbCrLf
                                            If LCase(oHeader.Name) = LCase("Disposition") Then
                                                'MessageBox.Show oHeader.Value
                                            ElseIf LCase(oHeader.Name) = LCase("warning") Then
                                                nMdnResult = 1
                                                sErrorMsg = sErrorMsg & oHeader.Value & vbCrLf
                                            ElseIf LCase(oHeader.Name) = LCase("error") Then
                                                nMdnResult = 2
                                                sErrorMsg = sErrorMsg & oHeader.Value & vbCrLf
                                            End If

                                        Next    'Each oHeader In oHeaders

                                        ' Verify MIC from the receiver.

                                        oHeader = oHeaders.GetHeaderByName("Received-Content-MIC")
                                        If Not oHeader Is Nothing Then

                                            Dim sRecvMicFldValue As String

                                            sRecvMicFldValue = oHeader.Value

                                            Dim lPos As Long
                                            lPos = InStr(sRecvMicFldValue, ",")
                                            If lPos = 0 And Len(sRecvMicFldValue) > 0 Then
                                                MessageBox.Show("Invalid Received-Content-MIC field value")
                                                Dim sMicValue As String
                                                Dim sMicAlg As String

                                                sMicValue = Mid(sRecvMicFldValue, 1, lPos - 1)
                                                sMicAlg = Mid(sRecvMicFldValue, lPos + 1)

                                                ' Compare the MIC of the subject document to MIC received by received.
                                                If sMicValue <> sSubjMicValue Then
                                                    MessageBox.Show("Recipient received invalid document. Subject MIC=" & sSubjMicValue & ", Recv MIC=" & sMicValue)
                                                End If

                                            End If

                                        End If

                                    End If


                                End If


                            Next    'ii

                            oMDN.Save(sPath & "Output\Received_MDN.Txt")


                        End If  'ckReceiveMdn.Value = 1 And ckAsynchronous.Value = 0

                        Label1.Text = ""

                        cmdViewAs2.Enabled = True

                        If nMdnResult = 0 Then
                            MessageBox.Show("Successfully sent.")
                        ElseIf nMdnResult = 1 Then
                            MessageBox.Show("The message was successfully sent but there were warnings.")
                            MessageBox.Show(sErrorMsg, "MDN Warning")

                        ElseIf nMdnResult = 2 Then
                            MessageBox.Show("An error occurred during transmission")
                            MessageBox.Show(sErrorMsg, "MDN Error")
                        End If


                    End If  'oMailDocument.Save(sPath & "Output\Sent_File.txt") <> 1

                End If  'oSubjMsg.Prepare <> 1

            End If  'oSubjMsg.Import(sPath & cmbFile.Text) <> 1


            Me.Cursor = Cursors.Default

        Catch ex As System.Exception
            txtNotification.Text = txtNotification.Text & Chr(13) & Chr(10) & "Severe error. " & ex.Message
        End Try
        Me.Cursor = Cursors.Default

    End Sub

    Click here to download a trial version of the Framework EDI