Archive for category windows

MD5 HMAC with VBA or VB. Visual Basic brought me back

Hi blog. Long time no see.

I searched some time for hmac md5 creation in VBA or VB, to be able to send hmac signed data with Excel,Access or Word. Eventually i found some code in the net and put them together, and now it works.
So if you want to connect to a REST webservice, that uses hmac with md5, from any Microsoft Office Program, this little functions may be useful to you.
For creating a signature the code first uses the cryptography functions of the system. The return value is a byte array, so if you want to see the md5 you have to transform that byte array in to readable md5. That is what the little helper function ByteArrayToHex() is for.

' Reference: http://stackoverflow.com/questions/8246340/does-vba-have-a-hash-hmac
Public Function hash_HMACMD5(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)

    Dim asc As Object, enc As Object
    Dim TextToHash() As Byte
    Dim SharedSecretKey() As Byte
    Set asc = CreateObject("System.Text.UTF8Encoding")
    Set enc = CreateObject("System.Security.Cryptography.HMACMD5")

    TextToHash = asc.Getbytes_4(sTextToHash)
    SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
    enc.Key = SharedSecretKey

    Dim bytes() As Byte
    bytes = enc.ComputeHash_2((TextToHash))

    hash_HMACMD5 = ByteArrayToHex(bytes)
    Set asc = Nothing
    Set enc = Nothing

End Function

' Referenz: http://www.vbforums.com/showthread.php?559398-Byte-array-to-hex-string
Private Function ByteArrayToHex(ByRef ByteArray() As Byte) As String
    Dim l As Long, strRet, Val As String
    For l = LBound(ByteArray) To UBound(ByteArray)
        Val = Hex$(ByteArray(l))
        If Len(Val) <> 2 Then
             Val = "0" & Val
        End If
        strRet = strRet & Val
    Next l
    ByteArrayToHex = LCase(strRet)
End Function

Use it like this:

hmac = hash_HMACMD5(“My Text i want to hash today”, “MY_TOTAL_SECRET_SECRET”)

, ,

Leave a comment

It works! HP Laserjet 1000 + Windows 7 = driver problem, virtualbox + ubuntu + cups = the solution

Recently my sister bought a new laptop as her old PC with Win 2k on it gets ready for a museum.
She asked me to find drivers for her HP Laserjet 1000 for Win7 because she did not find a way to get it working. I neither had success with finding drivers. There are some people saying the Vista driver works for them and others saying the XP driver work, but i did not find a confirmation and can not confirm it myself.
She prints only seldom so a new printer would not make much sense as the Laserjet is fully functional. And my sister is fine if printing is not as comfortable because of this seldom usage, so i had the idea to make the Laserjet working by an indirection over CUPS and i can tell you: It works.

Here are the shortened steps:

  • Get Virtualbox from: www.virtualbox.org
  • Install Virtualbox on your Windows 7 machine
  • Add a new Virtual Machine in Virtualbox for your Ubuntu installation
  • Add an USB Filter in Virtualbox for your printer to this Virtual Machine
  • Install Ubuntu Server 10.04 in a virtual machine (I had chosen Ubuntu 11.04*1 Server, but there is some script missing so i would suggest 10.04) . Install it with “CUPS” in the software selection.
  • Install “foo2zjs”. This is needed for the Laserjet 1000. on the ubuntu command line its a simple sudo apt-get install foo2zjs
  • Make remote configuration of CUPS possible with sudo cupsctl --remote-admin
  • Configure CUPS through the webinterface now reachable from your Windows browser on port 631. URL for your browser should look something like http://YOURVIRTUALMACHINE:631
  • As driver for your Laserjet choose the foomatic foo2zjs driver
  • Now if you are able to get your first test page printed from the web interface you are ready on the linux side
  • Add a new Printer in Windows, choose “Network Printer”, URL for the printer should look like http://YOURVIRTUALMACHINE:631/printers/HP_Laserjet_1000 You can copy the url from your Webinterface. If you copy and paste it, be sure you copy the http link not the https one
  • As Printer Driver choose “generic->MS Publisher Imagesetter”
  • Print a test page from your windows machine.

Additional notes:
My sister has to start the VM before she switches on/connects the printer. If you have an idea about that, leave me a comment.
Its no big problem cause starting the VM is just a double click on the VM image. You may start it headless if you dont like to get a window or even start it on system boot. I leave this as an exercise for you ๐Ÿ˜‰

*1:
I had some problems in Ubuntu 11.04 to install the printer driver for the Laserjet 1000 and tested some things, but dont know which one was the necessary step, so i list them here in random order:

These two come from http://wiki.ubuntuusers.de/HP_Laserjet_10xx The getweb command did not work for me as described in the wiki, and i copied some files to other places, but do not know if this helped, or was just needless.

9 Comments

%d bloggers like this: