Archive for category programming

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:
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:
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

mysql, umlauts and collation. Hey, o is not = ö

I came to a problem where mysql thinks that ö=o. So if your tables collation ist utf8_general_ci for example and you do

SELECT * FROM table WHERE some_field LIKE '%ö%'

You will get every row containing an “ö” but you also get every row containing an “o” (and vice versa btw).So if you really want to select the right rows you can go like this:

SELECT * FROM table WHERE some_field LIKE ('%ö%'  COLLATE utf8_bin)

Now you only get the rows containing “ö”.

Leave a comment

Short note: Running git repo with gitosis on non-standard ssh port

Just a short tip. If your ssh server is on a non-standard port other than port 22, maybe 8822 there are two ways if you manage your repositories with gitosis.
You can just add the port to yur git url like:

git clone ssh://

(Note: git clone without protocol specification wont work)

or create a file ~/.ssh/config containing

Port 8822


Leave a comment

The problem with choice

Tried to find a HTML to PDF generator for PHP the last few days … not easy.
I first found much about TCPDF. From the results it looked quite promising.
As it turns out it was not so easy to just put in your HTML like on the webpage, and get a good looking PDF.
After some testing i searched for alternatives and found DOMPDF. The render results for my page were much better than before with tcpdf. But as i tried a newer version it broke my layout completely (To be exact, somewhere between r305 and r309 of dompdf).
That lead me to submit a bug report. On the reported bugs i found someone pointing to another html2pdf php library: MPDF
mpdf does render my HTML good, too. It also prints some textboxes in the documents that dompdf did not. It has some other oddies, but seems quite nice till now.

The conclusion:
I yet not know which engine to choose. Till now dompdf and mpdf did the best job for me. dompdf produces a pdf with size of 6kb whereas mpdf uses 69kb. YMMV with different HTML, so you are on your own.
There are so many HTML to PDF engines out there, that it is not easy to choose. Thats only 3 i tested, and there are some more out there like fpdf, pdflib …
One of them is better on some tags, the other is better with some other. I keep wondering why not some of the engines could unite. More developers could mean better results. Lets assume there are 10 engines out inventing 10 wheels at the same time … what a waste of time.

Leave a comment

APC cache twice as fast as memcached if run on only one server

Ok, as i told yesterday i would try the cache wrapper today.
In my case APC with the wrapper is twice as fast as memcached, as i am running only one server. The wrapper gives very little overhead, but its worth it, because you can change the cache easily. Of course if you run more than one server memcached could be the one you want as it can distribute the cache over all machines.

Leave a comment

PHP wrapper class for cache engines | Neo22s

PHP wrapper class for cache engines | Neo22s.

Good to know this class called wrappercache. Within the next days  i will try this wrapper and will check the performance of my scripts that now use memcached.

1 Comment

Amazon EC2 to assist dedicated server?

We run a dedicated server at our work. As of the last posts about optimizing it for some special cases just another idea came to my mind:
How about letting an Amazon EC2 instance assist the dedicated server twice a year for just 2-3 hours?
Thats the only time it gets critical with the workload (mostly on the mysql database).
I yet dont know how, but if i get an idea on how this could be done i will post it here.
Maybe a replicated mysql instance, maybe a memcached instance on amazon? Would be quite cheap and could really help for just this little timeframe twice a year.

Leave a comment

%d bloggers like this: