Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

BizTalk Server 2006 : Pipeline Component Best Practices and Examples - Using PGP (part 2) - PGP Decode Component

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
1/23/2013 4:35:02 PM

PGP Decode Component

The following code example is the counterpart to the encoding component shown in the preceding subsection. The Decoding component is used on the receive side of BizTalk and is used when encrypted messages are received into BizTalk.

Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Diagnostics
Imports System.Drawing
Imports System.IO
Imports System.Reflection
Imports Microsoft.BizTalk.Component.Interop
Imports ABC.BizTalk.PipelineComponents.PGPUtilities


Namespace Microsoft.Utility.PipelineGnuPG

     <ComponentCategory(CategoryTypes.CATID_PipelineComponent),_
ComponentCategory(CategoryTypes.CATID_Decoder),_
System.Runtime.InteropServices.Guid("AEE2E180-8E4F-426d-9E39-C314E09F977E")> _
     Public Class PGPDecodeComponent


     Implements IBaseComponent, Microsoft.BizTalk.Component.Interop.IComponent,_
Microsoft.BizTalk.Component.Interop.IPersistPropertyBag, IComponentUI

     ' Component information
#Region "IBaseComponent"
     <Browsable(False)> _
Public ReadOnly Property Name() As String
    Get
       Return "PGP decoder"
    End Get
End Property
<Browsable(False)> _
Public ReadOnly Property Version() As String
    Get
       Return "1.0"
    End Get
End Property

					  

<Browsable(False)> _
Public ReadOnly Property Description() As String
     Get
       Return "PGG Decode Pipeline Component"
     End Get
End Property
<Browsable(False)> _
Public ReadOnly Property Icon() As System.IntPtr
     Get
       Return (CType(resourceManager.GetObject("IconBitmap"),_
Bitmap)).GetHicon()
     End Get
End Property
#End Region


       Private resourceManager As System.Resources.ResourceManager = New_
System.Resources.ResourceManager("ABC.BizTalk.PipelineComponents",_
System.Reflection.Assembly.GetExecutingAssembly())
       ' Property: Passphrase
       Private _passphrase As String
       Public Property Passphrase() As String
          Get
              Return _passphrase
       End Get
       Set(ByVal value As String)
           _passphrase = value
       End Set
End Property

      ' Property: GnuPGBinDir
      Private _PGPBinDirectory As String
      Public Property PGPBinDirectory() As String
      Get
             Return _PGPBinDirectory
      End Get
      Set(ByVal value As String)
          _PGPBinDirectory = value
      End Set
End Property

Private Function Decode(ByVal inStream As System.IO.Stream) As Stream
    Dim inFile As String = Path.GetTempFileName()
    Dim outFile As String = Path.ChangeExtension(inFile, "txt")

					  

Try
    DumpStreamToFile(inStream, inFile)
    Dim GPG As GnuPGWrapper = New GnuPGWrapper(_PGPBinDirectory)
    Dim GPGCommand As GnuPGCommand = GPG.Command
    GPGCommand.Command = Commands.Decrypt
    GPGCommand.InputFile = inFile
    GPGCommand.OutputFile = outFile
    GPGCommand.Passphrase = _passphrase
    'TODO: support encrypted passphrase, no passphrase is a security
    'risk

GPG.Execute(Nothing)

    outStream = ReadFileToMemoryStream(outFile)
Catch ex As Exception
    System.Diagnostics.Debug.WriteLine(ex)
Throw ex
    Finally
         If File.Exists(inFile) Then
         File.Delete(inFile)
    End If

    If File.Exists(outFile) Then
       File.Delete(outFile)
    End If
End Try

    Return outStream
End Function

#Region "IPersistPropertyBag Members"

Public Sub InitNew()
End Sub

Public Sub GetClassID(<System.Runtime.InteropServices.Out()> ByRef _
classID As Guid)

     classID = New Guid("4FC12033-D0BD-4298-BB31-FBDBA72F5961")
End Sub

Public Sub Load(ByVal propertyBag As IPropertyBag, ByVal _
errorLog As Integer)
    Dim text As String

					  

text = CStr(ReadPropertyBag(propertyBag, "Passphrase"))
    If Not text Is Nothing Then
          _passphrase = text
       End If
text = CStr(ReadPropertyBag(propertyBag, "PGPBinDirectory"))
If Not text Is Nothing Then
          _PGPBinDirectory = text
       End If
   End Sub

   Public Sub Save(ByVal propertyBag As IPropertyBag, ByVal clearDirty As_
Boolean, ByVal saveAllProperties As Boolean)
       Dim val As Object
       val = CObj(_passphrase)
       WritePropertyBag(propertyBag, "Passphrase", val)

       val = CObj(_PGPBinDirectory)

       WritePropertyBag(propertyBag, "PGPBinDirectory", val)
End Sub

#End Region

#Region "IComponent Members"

         Public Function Execute(ByVal pContext As IPipelineContext, ByVal pInMsg As_
Microsoft.BizTalk.Message.Interop.IBaseMessage) As_
Microsoft.BizTalk.Message.Interop.IBaseMessage
           Try
                If Not pInMsg Is Nothing Then
                   Dim originalStream As Stream =_
pInMsg.BodyPart.GetOriginalDataStream()
                   pInMsg.BodyPart.Data = Decode(originalStream)
                   pContext.ResourceTracker.AddResource(pInMsg.BodyPart.Data)
               End If
       Catch ex As Exception
            System.Diagnostics.Debug.WriteLine("Exception caught in_
ABC.BizTalk.PipelineComponents.PGPDecodeComponent::Execute:"& ex.Message)
            Throw ex
       End Try
       Return pInMsg
   End Function

#End Region

					  

#Region "IComponentUI Members"


        '<summary>
        'The Validate method is called by the BizTalk Editor during the build
        'of a BizTalk project.
        '</summary>
        '<param name="obj">An Object containing the configuration
         properties.</param>
        '<returns>The IEnumerator enables the caller to enumerate through a_
        'collection of strings containing error messages. These error messages
appear

        'as compiler error messages. To report successful property validation, the
        'method should return an empty enumerator.</returns>
        Public Function Validate(ByVal projectSystem As Object) As IEnumerator
        ' example implementation:
        ' ArrayList errorList = new ArrayList();
        ' errorList.Add("This is a compiler error");
        ' return errorList.GetEnumerator();
        Return Nothing
    End Function


#End Region

#Region "Utility Functions"
         Public Shared Sub DumpStreamToFile(ByVal fromStream As Stream, ByVal_
toFilename As String)
         Dim file As FileStream = Nothing
         Try
            file = New FileStream(toFilename, System.IO.FileMode.Create)
            Dim tmpBuff As Byte() = New Byte(4095) {}
            Dim bytesRead As Integer = 0
            bytesRead = file.Read(tmpBuff, 0, tmpBuff.Length)
            memStream.Write(tmpBuff, 0, bytesRead)

            Do While bytesRead <> 0
                  bytesRead = fromStream.Read(tmpBuff, 0, tmpBuff.Length)
                  file.Write(tmpBuff, 0, bytesRead)
            Loop

            file.Close()
            file = Nothing
      Finally
            If Not file Is Nothing Then
               file.Close()
             End If
         End Try
     End Sub

					  

Public Shared Function ReadFileToMemoryStream(ByVal fromFilename _
As String) As MemoryStream
      Dim file As FileStream = Nothing
      Try
          file = New FileStream(fromFilename, System.IO.FileMode.Open)
          Dim memStream As MemoryStream = New MemoryStream()
          Dim tmpBuff As Byte() = New Byte(4095) {}
          Dim bytesRead As Integer = 0
          bytesRead = file.Read(tmpBuff, 0, tmpBuff.Length)
          memStream.Write(tmpBuff, 0, bytesRead)

          Do While bytesRead <> 0
             bytesRead = file.Read(tmpBuff, 0, tmpBuff.Length)
             memStream.Write(tmpBuff, 0, bytesRead)
         Loop

         file.Close()
         file = Nothing

         memStream.Position = 0
         Return memStream
     Finally
          If Not file Is Nothing Then
             file.Close()
          End If
      End Try
  End Function

Public Shared Function ReadPropertyBag(ByVal pb As_
Microsoft.BizTalk.Component.Interop.IPropertyBag, ByVal propName As String) _
As Object

             Dim val As Object = Nothing

             Try
                pb.Read(propName, val, 0)
             Catch e1 As ArgumentException
                Return val
             Catch ex As Exception
                 Throw New ApplicationException(ex.Message)
                 End Try

             Return val
         End Function

        ''' <summary>
        ''' Writes property values into a property bag.
        ''' </summary>

					  

''' <param name="pb">Property bag.</param>
        ''' <param name="propName">Name of property.</param>
        ''' <param name="val">Value of property.</param>
        Public Shared Sub WritePropertyBag(ByVal pb As_
Microsoft.BizTalk.Component.Interop.IPropertyBag, ByVal propName As String, ByVal _
val As Object)
             Try
                pb.Write(propName, val)
             Catch ex As Exception
                Throw New ApplicationException(ex.Message)
             End Try
         End Sub

#End Region
    End Class
End Namespace				  
Other -----------------
- Microsoft Dynamics CRM 4.0 : Using Microsoft Dynamics CRM with Microsoft SharePoint
- Windows Server 2003 on HP ProLiant Servers : Defining the Windows 2003 Infrastructure
- Microsoft Content Management Server : Implementing Server-Side Validation
- Microsoft Content Management Server : Preventing Pages with Invalid Content from Being Saved
- Microsoft Systems Management Server 2003 : Permissions and Security Objects (part 2) - Assigning Permissions
- Microsoft Systems Management Server 2003 : Permissions and Security Objects (part 1)
- Microsoft Systems Management Server 2003 : Security - Accounts and Groups
- Windows Server 2003 on HP ProLiant Servers : Assessment of the Enterprise - Conducting the Assessment
- Windows Server 2003 on HP ProLiant Servers : Assessment of the Enterprise - The Assessment Team
- Windows Small Business Server 2011 : Disaster Planning - Preparing for a Disaster, Restoring from Backup
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer