Results 1 to 2 of 2

Thread: VBscript HMAC512SHA with Base64 encoded data script for ASP classic old webshop

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Location
    Holland
    Posts
    1

    VBscript HMAC512SHA with Base64 encoded data script for ASP classic old webshop

    I have this old webshop based on classis ASP that I want to use with Payment service provider Rabobank omnikassa 2 but I can's seem to find a script that I need that will accept HMAC512SHA encryption with a Base64 encoded key.
    The webshop is build in VBscript and I managed to find some code however this will not accept a Base64 encoded key. I alread have a Base64 decoder script but need to make changes to the script below or have something else.

    This is the code, I thisk that changes have to be made in line 44 at the marker ### to accept base64coded or decoded key, can't use UTF-8 string input.

    <%
    ' Hash("sha512", "Hello World")
    ' Hash("sha512HMAC", Array("Hello World", "Shared Key"))

    Function Hash(HashType, Target)
    On Error Resume Next
    Dim PlainText

    If IsArray(Target) = True Then PlainText = Target(0) Else PlainText = Target End If

    ' create UTF-8 string
    With CreateObject("ADODB.Stream")
    .Open
    .CharSet = "Windows-1252"
    .WriteText PlainText
    .Position = 0
    .CharSet = "UTF-8"
    PlainText = .ReadText
    .Close
    End With

    Set UTF8Encoding = CreateObject("System.Text.UTF8Encoding")

    Dim PlainTextToBytes, BytesToHashedBytes, HashedBytesToHex
    PlainTextToBytes = UTF8Encoding.GetBytes_4(PlainText)

    Select Case HashType
    Case "md5": Set Cryptography = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider") '< 64 (collisions found)
    Case "ripemd160": Set Cryptography = CreateObject("System.Security.Cryptography.RIPEMD160Managed")
    Case "sha1": Set Cryptography = CreateObject("System.Security.Cryptography.SHA1Managed") '< 80 (collision found)
    Case "sha256": Set Cryptography = CreateObject("System.Security.Cryptography.SHA256Managed")
    Case "sha384": Set Cryptography = CreateObject("System.Security.Cryptography.SHA384Managed")
    Case "sha512": Set Cryptography = CreateObject("System.Security.Cryptography.SHA512Managed")
    Case "md5HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACMD5")
    Case "ripemd160HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACRIPEMD160")
    Case "sha1HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA1")
    Case "sha256HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA256")
    Case "sha384HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA384")
    Case "sha512HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA512")
    End Select

    Cryptography.Initialize()

    ' ### the line below does not accept bsae64 decoded string
    If IsArray(Target) = True Then Cryptography.Key = UTF8Encoding.GetBytes_4(target(1)) End If
    BytesToHashedBytes = Cryptography.ComputeHash_2((PlainTextToBytes))

    For x = 1 To LenB(BytesToHashedBytes)
    HashedBytesToHex = HashedBytesToHex & Right("0" & Hex(AscB(MidB(BytesToHashedBytes, x, 1))), 2)
    Next

    If Err.Number <> 0 Then Response.Write(Err.Description) Else Hash = LCase(HashedBytesToHex) End If
    On Error GoTo 0
    End Function
    %>

    Can anybody help me with this ?
    Al my other coding is done and I need to fix this, any suggestions.
    Thanks

  2. #2
    New Member
    Join Date
    Mar 2021
    Posts
    1

    Re: VBscript HMAC512SHA with Base64 encoded data script for ASP classic old webshop

    Hi there - I know this is an old post but did you ever come up with a solution? I'm having similar problems.


    Quote Originally Posted by Jean B View Post
    I have this old webshop based on classis ASP that I want to use with Payment service provider Rabobank omnikassa 2 but I can's seem to find a script that I need that will accept HMAC512SHA encryption with a Base64 encoded key.
    The webshop is build in VBscript and I managed to find some code however this will not accept a Base64 encoded key. I alread have a Base64 decoder script but need to make changes to the script below or have something else.

    This is the code, I thisk that changes have to be made in line 44 at the marker ### to accept base64coded or decoded key, can't use UTF-8 string input.

    <%
    ' Hash("sha512", "Hello World")
    ' Hash("sha512HMAC", Array("Hello World", "Shared Key"))

    Function Hash(HashType, Target)
    On Error Resume Next
    Dim PlainText

    If IsArray(Target) = True Then PlainText = Target(0) Else PlainText = Target End If

    ' create UTF-8 string
    With CreateObject("ADODB.Stream")
    .Open
    .CharSet = "Windows-1252"
    .WriteText PlainText
    .Position = 0
    .CharSet = "UTF-8"
    PlainText = .ReadText
    .Close
    End With

    Set UTF8Encoding = CreateObject("System.Text.UTF8Encoding")

    Dim PlainTextToBytes, BytesToHashedBytes, HashedBytesToHex
    PlainTextToBytes = UTF8Encoding.GetBytes_4(PlainText)

    Select Case HashType
    Case "md5": Set Cryptography = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider") '< 64 (collisions found)
    Case "ripemd160": Set Cryptography = CreateObject("System.Security.Cryptography.RIPEMD160Managed")
    Case "sha1": Set Cryptography = CreateObject("System.Security.Cryptography.SHA1Managed") '< 80 (collision found)
    Case "sha256": Set Cryptography = CreateObject("System.Security.Cryptography.SHA256Managed")
    Case "sha384": Set Cryptography = CreateObject("System.Security.Cryptography.SHA384Managed")
    Case "sha512": Set Cryptography = CreateObject("System.Security.Cryptography.SHA512Managed")
    Case "md5HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACMD5")
    Case "ripemd160HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACRIPEMD160")
    Case "sha1HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA1")
    Case "sha256HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA256")
    Case "sha384HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA384")
    Case "sha512HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA512")
    End Select

    Cryptography.Initialize()

    ' ### the line below does not accept bsae64 decoded string
    If IsArray(Target) = True Then Cryptography.Key = UTF8Encoding.GetBytes_4(target(1)) End If
    BytesToHashedBytes = Cryptography.ComputeHash_2((PlainTextToBytes))

    For x = 1 To LenB(BytesToHashedBytes)
    HashedBytesToHex = HashedBytesToHex & Right("0" & Hex(AscB(MidB(BytesToHashedBytes, x, 1))), 2)
    Next

    If Err.Number <> 0 Then Response.Write(Err.Description) Else Hash = LCase(HashedBytesToHex) End If
    On Error GoTo 0
    End Function
    %>

    Can anybody help me with this ?
    Al my other coding is done and I need to fix this, any suggestions.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width