Friday, March 25, 2011

Firefox4 on 64 bit Ubuntu

Now that Firefox 4 final is out, I wanted to switch to using it rather than version 3.x on my Ubuntu 10.10 systems. You can download a Linux version of Firefox 4.0 from the Mozilla site, but it's 32-bit only. While it will run, the problem I found is that all of my plugins (libflashplayer, etc) stopped working. The solution is to install the 64-bit build of Firefox 4, which is available on a launchpad PPA. Thus:

sudo apt-add-repository ppa:mozillateam/firefox-stable 
sudo apt-get update
sudo apt-get upgrade

That gave me a new, working FireFox 4.0. Most of my extensions worked OK, with the exception of del.icio.us (fix here), and All-in-one sidebar (now uninstalled). And, weirdly, the language packs aren't compatible between 3.x and 4.0, but I assume that will get sorted in time.

Thursday, March 24, 2011

Quick tip: SHA1 or MD5 checksum strings in Java

In a recent project (OK, I was processing FOAF data), I needed to be able to generate the hex-encoded string of a SHA1 checksum. The built-in Java security classes can do the heavy-lifting, of generating the checksum itself, but they deliver the resulting checksum as a byte-array. I needed the string encoding of that array. There are various code-snippets around on the web to do that, by iterating over the byte array and incrementally building up the string in a buffer, but they look low-level and inelegant. The following is much neater (written for SHA1, but the method works for the other digest formats):

public String getEncodedSha1Sum( String key ) {
    try {
        MessageDigest md = MessageDigest.getInstance( "SHA1" );
        md.update( key.getBytes() );
        return new BigInteger( 1, md.digest() ).toString(16);
    }
    catch (NoSuchAlgorithmException e) {
        // handle error case to taste
    }
}

Kudos to Brian Gianforcaro on StackOverflow for the tip