MD5 HMAC with VBA. Visual Basic brought me back

Hi blog. Long time no see.

I searched some time for hmac md5 creation in VBA, 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 need hmac signature in Microsoft Office feel free to use this code:

' 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

Blender: cycles renderer and CUDA in Ubuntu 12.10 on nvidia GPU

If you want to run blender ootb in ubuntu with CUDA support you will make a sad face at first.

Maybe at first you search for the preference for CUDA like its stated in the internet under “User-Preferences->System”, and dont find it. Then maybe you have a look at the addons for the cycles renderer and will see an error message stating “missing script files”. If you then try the version from debian (Step 1 and 2 in this guide) and install CUDA (Step 3), as render result you will only get a black screen, and maybe you will find the error message “error — unsupported GNU version! gcc 4.7 and up are not supported!” so cuda kernel compilation failed. So this is what step 4 in this guide is for.

Maybe this is going to change as 12.10 is still in beta, if not, follow this steps. I dont know if it also works for other Ubuntu versions as 12.04 Precise Pangolin.

There the two problems as of now are:

  • The blender in in current ubuntu packages does not support CUDA with cycles renderer.
  • CUDA needs gcc version <4.7, but on Quetzal version 4.7 is default, so CUDA fails to compile.

You need to have the proprietary nvidia drivers and some additional Packages installed:

sudo apt-get install nvidia-current build-essential gcc-4.6 freeglut3-dev

1. Download and install blender 2.63a-2 from the debian-experimental repository. As it depends on 2 packages that are newer in debian experimental, you have to download two additional packages, namely libglew1.7 and libpng15-15. Choose the right .deb package for your architecture (i386 or amd64 would be the most common depending if you are on 32 or 64 bit) from the following sites:

Blender: http://packages.debian.org/experimental/blender

libglew: http://packages.debian.org/sid/libglew1.7
* Edit, libpng package changed, thx to majorkillsmurfsmrblurgle in the comments*
libpng: http://snapshot.debian.org/package/libpng/1.5.11-1/#libpng15-15_1.5.11-1

2. Install the packages with dpkg. For me the command is

sudo dpkg -i blender_2.63a-2_amd64.deb libglew1.7_1.7.0-3_amd64.deb \
     libpng15-15_1.5.11-1_amd64.deb

3. Get CUDA toolkit from nvidia and install it by running the installer. Get the right package from http://developer.nvidia.com/cuda/cuda-downloads and install it to the default location (if you change the location consider this in step 3) For Quetzal you can use the CUDA toolkit for Ubuntu 11.04

Install the toolkit with:

chmod +x cudatoolkit_4.2.9_linux_64_ubuntu11.04.run
sudo ./cudatoolkit_4.2.9_linux_64_ubuntu11.04.run

4. Link gcc4.6 to the CUDA installation, so it does not use the default 4.7

sudo ln -s /usr/bin/gcc-4.6 /usr/local/cuda/bin/gcc

So thats it.

, ,

15 Comments

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

jQuery.load does not work in Internet Explorer sometimes, check your HTML

Searched a while to find this. If you use jQuery.load(“site”) to add dynamic data, be sure you checked the response for html errors.
In my case i did not know exactly which little mistake made the Internet Explorer not load and insert the code to my DOM, but after tidying it up with the help of HTML-Validator in Firefox, now it works.
Now i know that it was one closing div tag too much in the dynamic loaded data. IE 8 is not tolerant at this and its hard to debug if you dont know this.

, ,

Leave a comment

Disable the boot video with shaking hands on Nokia N900

I did not remember howto disable the boot video on my N900. I searched some time as most of the instructions were for using another video, not disabling, and i was not shure if just removing may end up in an unbootable device.

So to come to an end, i found how to disable the video here

You have to edit /etc/hildon-welcome.d/default.conf that it looks like this:

[hildon-welcome]
# filename=Hands-v32-h264.avi

Like in most Linux config files the # is for commenting the line in Maemo, too.

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://git@myserver.com:8822/repo.git

(Note: git clone git@myserver.com:8822/repo.git without protocol specification wont work)

or create a file ~/.ssh/config containing

Host myserver.com
Port 8822

Source: https://wiki.archlinux.org/index.php/Gitosis#Non-standard_SSH_port

Leave a comment

Finally the trouble with my HVR-1300 under Linux and mythtv seem to be over

I got my mythtv backend running for years now, but since mythtv switched to S2-API, the mythtv backend failed to lock to channels. Some other DVB applications had these problems, too, like kaffeine. I quickly found which patch had to be reverted to get it working again. Without knowing what i did, but it did work, so it was ok for me. Darron Broad was a big help at that time for getting everything in a good shape.

A few weeks ago i bought a dvb-t stick as i was tired of recompiling. A Terratec Cynergy T-Stick RC (MKIII) (Device ID:0097) as i thought it should work out of the box … well that was a mistake. The first i bought was defect. I switched it for a new one, it works some time and then stops working until you switch your PC off and on again. It is known, but no fix in sight. So it was from pest to cholera.

Now finally Devin Heitmueller found the real bug for the HVR-1300, HVR-3000 and HVR-4000 (as far as i can judge this, he seems to know what he is doing in contradiction to me). If that patch gets into the kernel i finally do not need to recompile the kernel after every update. Thanks Devin for that finding. I dont mind the DVB penstick if the HVR patch gets into the kernel.
The “pest” seems to be cured, i now still have my “cholera” lying around, but maybe sometimes someone finds a cure for that, too. I also got a Pinnacle 7010iX lying around here that is known to have no linux support at this time. Maybe i can use it in 10 Years when there is no more DVB-T ;)

A Final thought:
Although you hear a lot of “linux supports more hardware than windows” you see that “supports” does not mean “does work” in every case. Its not the linux developers fault in most cases, its just the manufacturer that dont help in driver development. But searching the web before buying not always leads to the correct hardware. I bought the Terratec as they seem to support linux a little bit, at least, and after years with my HVR-1300 and patching the kernel everytime was unhappy about hauppauge not helping in getting that card to work.

*edit*
Now the patch is in the kernel since version 3.0. In ubuntu oneiric (11.10) i can now run a stock kernel as of linux-image-3.0-7. Thanks,thanks, thanks.

Leave a comment

Follow

Get every new post delivered to your Inbox.

Join 155 other followers

%d bloggers like this: