Click here to Skip to main content
15,887,267 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionPublic Delegate Sub Action(Of T) (obj As T) Pin
Member 1171394230-Jun-15 20:23
Member 1171394230-Jun-15 20:23 
AnswerRe: Public Delegate Sub Action(Of T) (obj As T) Pin
Richard MacCutchan30-Jun-15 21:21
mveRichard MacCutchan30-Jun-15 21:21 
QuestionFirstData G4 V14 HMAC Header Pin
jkirkerx29-Jun-15 13:47
professionaljkirkerx29-Jun-15 13:47 
AnswerRe: FirstData G4 V14 HMAC Header Pin
Jörgen Andersson29-Jun-15 20:17
professionalJörgen Andersson29-Jun-15 20:17 
GeneralRe: FirstData G4 V14 HMAC Header Pin
jkirkerx30-Jun-15 6:49
professionaljkirkerx30-Jun-15 6:49 
GeneralConclusion - XMLWriter, UTF16 and XML empty element short form. Pin
jkirkerx5-Jul-15 8:54
professionaljkirkerx5-Jul-15 8:54 
AnswerRe: FirstData G4 V14 HMAC Header - Issue 1: Pin
jkirkerx30-Jun-15 11:10
professionaljkirkerx30-Jun-15 11:10 
GeneralUpdate - got the calc to work now with the request message Pin
jkirkerx1-Jul-15 7:38
professionaljkirkerx1-Jul-15 7:38 
So I finally figured out how to just get the Body of the Message, and calc against it, and veriffied it in the FirstData API Tool
I removed the msg.WriteStartHeader and the end element to just get the body only.
Still can't authenticate, but I checked the response message, and the new elements were not there.
So now I'm down to that part, hopefully I'll figure it out today, then it should work properly.
Public Function BeforeSendRequest( _
        ByRef request As Message,
        ByVal channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest

        Dim buffer As MessageBuffer = request.CreateBufferedCopy(Int32.MaxValue)
        request = buffer.CreateMessage

        Dim msg As Message = buffer.CreateMessage
        Dim encoder As ASCIIEncoding = New ASCIIEncoding

        Dim sb As StringBuilder = New StringBuilder
        Dim xmlSettings As New XmlWriterSettings
        xmlSettings.OmitXmlDeclaration = True

        Dim xmlWriter As XmlWriter = xmlWriter.Create(sb, xmlSettings)
        Dim writer As XmlDictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter)

        'Just grab the body of the request to generate the HMAC
        msg.WriteStartBody(writer)
        msg.WriteBodyContents(writer)
        xmlWriter.WriteEndElement()
        writer.Flush()

        Dim body As String = sb.ToString.Replace(" />", "/>")
        Dim xml_bytes() As Byte = encoder.GetBytes(body)

        'SHA1 hash on XML string
        Dim sha1_crypto As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider
        Dim hash As String = BitConverter.ToString(sha1_crypto.ComputeHash(xml_bytes)).Replace("-", "")
        Dim hashed_content As String = hash.ToLower

        'assign values to hashing and header variables
        Dim m_method As String = "POST"
        Dim m_type As String = "text/xml"
        Dim m_time As String = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
        Dim m_hashData As String = m_method & vbLf & m_type & vbLf & hashed_content & vbLf & m_time & vbLf & _endPoint_Uri

        'Compute the HMAC and convert to a base64 hash
        Dim m_hmac_sha1 As HMAC = New HMACSHA1(Encoding.UTF8.GetBytes(_hmac))
        Dim m_hmac_data() As Byte = m_hmac_sha1.ComputeHash(Encoding.UTF8.GetBytes(m_hashData))
        Dim m_base64_hash As String = Convert.ToBase64String(m_hmac_data)

        Dim httpRequestMessage As HttpRequestMessageProperty
        Dim httpRequestMessageObject As Object = Nothing

        'This part must not be working - The header elements just wont add to the message
        If request.Properties.TryGetValue(HttpRequestMessageProperty.Name, httpRequestMessageObject) Then
            'This block never runs, but is here in case the condition is true
            httpRequestMessage = CType(httpRequestMessageObject, HttpRequestMessageProperty)
            httpRequestMessage.Headers("x-gge4-date") = m_time
            httpRequestMessage.Headers("x-gge4-content-sha1") = hashed_content
            httpRequestMessage.Headers("authorization") = "gge4_api " & _keyID & ":" & m_base64_hash

        Else
            'This code block here doesn't seem to add the header elements
            httpRequestMessage = New HttpRequestMessageProperty
            httpRequestMessage.Headers("x-gge4-date") = m_time
            httpRequestMessage.Headers("x-gge4-content-sha1") = hashed_content
            httpRequestMessage.Headers("authorization") = "gge4_api " & _keyID & ":" & m_base64_hash
            request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage)

        End If

        Return Nothing

    End Function

AnswerCan't get the hashed content right Pin
jkirkerx1-Jul-15 12:39
professionaljkirkerx1-Jul-15 12:39 
QuestionExecute multiple sql queries with one database hit Pin
satc27-Jun-15 19:53
satc27-Jun-15 19:53 
AnswerRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre27-Jun-15 22:04
professionalSascha Lefèvre27-Jun-15 22:04 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc27-Jun-15 22:49
satc27-Jun-15 22:49 
GeneralRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre27-Jun-15 23:15
professionalSascha Lefèvre27-Jun-15 23:15 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc27-Jun-15 23:28
satc27-Jun-15 23:28 
GeneralRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre28-Jun-15 1:11
professionalSascha Lefèvre28-Jun-15 1:11 
GeneralRe: Execute multiple sql queries with one database hit Pin
Dave Kreskowiak28-Jun-15 2:17
mveDave Kreskowiak28-Jun-15 2:17 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc28-Jun-15 2:20
satc28-Jun-15 2:20 
GeneralRe: Execute multiple sql queries with one database hit Pin
Dave Kreskowiak28-Jun-15 10:40
mveDave Kreskowiak28-Jun-15 10:40 
GeneralRe: Execute multiple sql queries with one database hit Pin
Dave Kreskowiak28-Jun-15 2:09
mveDave Kreskowiak28-Jun-15 2:09 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc28-Jun-15 2:12
satc28-Jun-15 2:12 
QuestionCreate a kind of "recovery script" for a deleted object in Entity Pin
satc27-Jun-15 19:06
satc27-Jun-15 19:06 
AnswerRe: Create a kind of "recovery script" for a deleted object in Entity Pin
Dave Kreskowiak27-Jun-15 19:34
mveDave Kreskowiak27-Jun-15 19:34 
GeneralRe: Create a kind of "recovery script" for a deleted object in Entity Pin
satc27-Jun-15 19:40
satc27-Jun-15 19:40 
GeneralRe: Create a kind of "recovery script" for a deleted object in Entity Pin
Richard MacCutchan27-Jun-15 21:16
mveRichard MacCutchan27-Jun-15 21:16 
GeneralRe: Create a kind of "recovery script" for a deleted object in Entity Pin
satc27-Jun-15 22:34
satc27-Jun-15 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.