Archive for July, 2007

MD5 and SHA hashing in Java

Monday, July 9th, 2007
MD5 and SHA are two popular hashing algorithms with a variety of uses. An implementation of these algorithms is included in J2SE, under the java.security package.

Pretty often you may need to store some information in encrypted form, like a password stored in a database. You can use the MD5 algorithm to encrypt the original String and then safely store it in the database. Later, you authenticate by comparing the digests. This sample code returns the MD5 digest of a String:

public static byte[] md5( String st )
throws NoSuchAlgorithmException
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(st.getBytes());
return md5.digest();
}


You may also need to calculate the MD5 digest of the contents of a whole file (exactly as the md5 unix command does). This is useful in file integrity checks. In this case you have to read chunks from the file and repeatedly call the update() method. This way you avoid loading the whole of large files into memory. Here is some sample code:

public static byte[] md5( File file )
throws NoSuchAlgorithmException, IOException
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
InputStream in = new FileInputStream(file);
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) > 0)
md5.update(buffer,0,count);
return md5.digest();
}


The above methods return the digest as a 16-byte-long array of bytes. You can get the corresponding hexadecimal representation using this method:

public static String byteArrayToHex( byte[] bytes )
{
StringBuilder builder =
new StringBuilder(bytes.length*2);
for (byte b : bytes)
builder.append(Integer.toHexString((b & 0xFF) +
0x100).substring(1));
return builder.toString();
}


To switch to the SHA hashing algorithm you simply have to pass "SHA" in the getInstance() method.

Acer Smart Line Backpack

Friday, July 6th, 2007

acer smart line backpack


I'm just so excited about me new laptop backpack that I want to tell everybody about it! It has been a while since I have been thinking of replacing my laptop's case with a backpack, because that would be more convenient when travelling by motorcycle, and yesterday I finally made it to go to the shops and check out what was available.I went to lots of shops (both computer shops and motorcycle accessories) and I finally met my destiny at RAM Shop, Eksarhia. I saw it sitting on a shelf, looking at me, shouting at me: "hey right here! I am what you were looking for!". In fact, it was far beyond my expectations!

Acer Smart Line Backpack has a massive main interior that can easily accommodate not one but two 15.4" laptop computers! A nice surprise was the special big envelope that can optionally host the computer, for increased protection. The envelope is safely attached into the bag with the help of hook and loop fasteners. There is also a broad accessories pocket, two smaller pockets on the front, and two generous side pockets. In a pinch, this sack can hold virtually everything! There is soft filling material everywhere that will protect the fragile equipment from a fall.

The guy in the shop was honest enough to admit that the bag is not 100% waterproof, but he assured me that it can handle a soft rainfall. In fact, the bag is waterproof. Some days after the purchase and while showing off my new bag to some friends, I accidentally discovered something that even the salesman didn't know. There was one more hidden pocket on the bottom of the bag which hosts a huge hood capable of fully covering the bag. Now how cool is that?

The price was a little high (like €85) but I think it deserves it, till the last cent. Definitely the best bag I have ever owned.

Spread the word: Quit Your Job

Thursday, July 5th, 2007
A smiling sun wearing sunglasses surrounded by the motto “Today is a great day to quit your job”Yeah I know how desperately you want to do it... And do you know when is the perfect day to do it? That's right! TODAY!

But, of course, it is not that easy to quit your job. So, if you are not willing to follow my encouragements and decide keeping your job for the time being, at least you have a chance to express yourself. In this shop you can find a wide variety of products that will remind you (and the others) what day is today.