VB6 sha512 sign from secret key and return URL -Any Solution

Hello

Required is any code and or Dll or any solution to digitally sign a url with a secret api-key and Post it back to the server that can work in VB6

This is an Example in PHP  , need some type of hash_hmac equivalence in VB6 and example if possible.

$apikey='xxx';
$apisecret='xxx'; 
$nonce=time(); 
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce; 
$sign=hash_hmac('sha512',$uri,$apisecret); 
$ch = curl_init($uri); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign)); 
$execResult = curl_exec($ch); 
$obj = json_decode($execResult);

Open in new window


For a more exact definition , I have a another question posted here that is kinda different since its is as far as I am on my own  
trying to solve this, but i think this is worthy as separate question .
Please I really need something that will work in vb6.

Thank You Experts
bill smilyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi bill,

I have taken the code from: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.hmacsha512?view=netframework-4.7.2

Please do check the documentation so that it becomes easier when you actually implement the code.

Imports System
Imports System.IO
Imports System.Security.Cryptography

Public Class HMACSHA512example
    Public Shared Sub Main(ByVal Fileargs As String())
        Dim dataFile As String
        Dim signedFile As String

        If Fileargs.Length < 2 Then
            dataFile = "text.txt"
            signedFile = "signedFile.enc"

            If Not File.Exists(dataFile) Then

                Using sw As StreamWriter = File.CreateText(dataFile)
                    sw.WriteLine("Here is a message to sign")
                End Using
            End If
        Else
            dataFile = Fileargs(0)
            signedFile = Fileargs(1)
        End If

        Try
            Dim secretkey As Byte() = New Byte(63) {}

            Using rng As RNGCryptoServiceProvider = New RNGCryptoServiceProvider()
                rng.GetBytes(secretkey)
                SignFile(secretkey, dataFile, signedFile)
                VerifyFile(secretkey, signedFile)
            End Using

        Catch e As IOException
            Console.WriteLine("Error: File not found", e)
        End Try
    End Sub

    Public Shared Sub SignFile(ByVal key As Byte(), ByVal sourceFile As String, ByVal destFile As String)
        Using hmac As HMACSHA512 = New HMACSHA512(key)

            Using inStream As FileStream = New FileStream(sourceFile, FileMode.Open)

                Using outStream As FileStream = New FileStream(destFile, FileMode.Create)
                    Dim hashValue As Byte() = hmac.ComputeHash(inStream)
                    inStream.Position = 0
                    outStream.Write(hashValue, 0, hashValue.Length)
                    Dim bytesRead As Integer
                    Dim buffer As Byte() = New Byte(1023) {}

                    Do
                        bytesRead = inStream.Read(buffer, 0, 1024)
                        outStream.Write(buffer, 0, bytesRead)
                    Loop While bytesRead > 0
                End Using
            End Using
        End Using

        Return
    End Sub

    Public Shared Function VerifyFile(ByVal key As Byte(), ByVal sourceFile As String) As Boolean
        Dim err As Boolean = False

        Using hmac As HMACSHA512 = New HMACSHA512(key)
            Dim storedHash As Byte() = New Byte(hmac.HashSize / 8 - 1) {}

            Using inStream As FileStream = New FileStream(sourceFile, FileMode.Open)
                inStream.Read(storedHash, 0, storedHash.Length)
                Dim computedHash As Byte() = hmac.ComputeHash(inStream)

                For i As Integer = 0 To storedHash.Length - 1

                    If computedHash(i) <> storedHash(i) Then
                        err = True
                    End If
                Next
            End Using
        End Using

        If err Then
            Console.WriteLine("Hash values differ! Signed file has been tampered with!")
            Return False
        Else
            Console.WriteLine("Hash values agree -- no tampering occurred.")
            Return True
        End If
    End Function
End Class

Open in new window


Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
I am sorry Bill. I posted VB.Net code not VB6 code. One question though, any specific reason to use VB6?
0
bill smilyAuthor Commented:
An old Classic Visual Basic, VB6  project is required asap is being brought back into service, its the only part that needs a fix.

Old Timer Needs Help
(Decades ago we could post points,Im not sure how it works now, I am back from 20 years ago, how do I add incentive for experts .)
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Chinmay PatelChief Technical NinjaCommented:
I don't think this qualifies as a valid answer and you should not allocate any points to my answer. Now if you are asking in general, I think help section is ur best bet. I am sorry but I never used ask question feature so don't have the answer.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
(Decades ago we could post points,Im not sure how it works now, I am back from 20 years ago, how do I add incentive for experts .)
That IS old! EE hasn't allowed adding points in a looooooong time. I'm sure Chinmay can help ...
0
bill smilyAuthor Commented:
I think I found a w0rking example here
'https://fujori.com/wp-content/uploads/2018/02/bittrex_connect.txt

i think if.net framework installed it will work ok
I am testing this tonight

Public Function hashHmacSHA512(uri As String, apikey As String)
   
    Dim keyArray(64) As Byte
    Dim i As Long
    Dim text As Object
    Dim SHA512 As Object
    Dim xml As Object
   
    On Error GoTo erre5423:
   
    For i = 0 To 63
        keyArray(i) = Asc(Mid(apikey, i + 1, 1))
    Next
    On Error GoTo 0
   
    Set text = CreateObject("System.Text.UTF8Encoding")
    Set SHA512 = CreateObject("System.Security.Cryptography.HMACSHA512")
    Set xml = CreateObject("MSXML2.DOMDocument")
   
    SHA512.key = keyArray()
    xml.loadXML "<root />"
    xml.DocumentElement.DataType = "bin.Hex"
    xml.DocumentElement.nodeTypedValue = SHA512.ComputeHash_2((text.GetBytes_4(uri)))
    hashHmacSHA512 = Replace(xml.DocumentElement.text, vbLf, "")
Exit Function
erre5423:
MsgBox "err hashHmacSHA512 " & Err.Description
End Function
0
Chinmay PatelChief Technical NinjaCommented:
Hi Bill,

I found the link after I logged on to my computer - the earlier post was from my cell where it was hard to locate.

http://support.experts-exchange.com/customer/en/portal/articles/2527982-how-do-i-close-my-question-?b_id=44

In this case, your answer - if it works - will qualify as the answer. Please close the question accordingly.

Regards,
Chinmay.
0
bill smilyAuthor Commented:
Public Function hashHmacSHA512(uri As String, apikey As String)
     
     Dim keyArray(64) As Byte
     Dim i As Long
     Dim text As Object
     Dim SHA512 As Object
     Dim xml As Object
     
     On Error GoTo erre5423:
     
     For i = 0 To 63
         keyArray(i) = Asc(Mid(apikey, i + 1, 1))
     Next
     'On Error GoTo 0
     
     Set text = CreateObject("System.Text.UTF8Encoding")
     Set SHA512 = CreateObject("System.Security.Cryptography.HMACSHA512")
     Set xml = CreateObject("MSXML2.DOMDocument")
     
     SHA512.key = keyArray()
     xml.loadXML "<root />"
     xml.DocumentElement.DataType = "bin.Hex"
     xml.DocumentElement.nodeTypedValue = SHA512.ComputeHash_2((text.GetBytes_4(uri)))
     hashHmacSHA512 = Replace(xml.DocumentElement.text, vbLf, "")
 Exit Function
 erre5423:
 MsgBox "err hashHmacSHA512 " & Err.Description
 End Function
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bill smilyAuthor Commented:
if key is 32 long change 63 to 31
0
bill smilyAuthor Commented:
Chinmay tipped me on Security.Cryptography and from that I was able to

find a good vb example I posted above
0
Chinmay PatelChief Technical NinjaCommented:
Thank you bill :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.