Friday, September 21, 2007

Don't Change the World


A nice story for you...

Once upon a time, there was a king who ruled a prosperous country. One day, he went for a trip to some distant areas of his country.

When he was back to his palace, he complained that his feet were very painful, because it was the first time that he went for such a long trip, and the road that he went through was very rough and stony. He then ordered his people to cover every road of the entire country with leather. Definitely, this would need thousands of cows' skin, and would cost a huge amount of money.

Then one of his wise servant dared himself to tell the king, "Why do you have to spend that unnecessary amount of money ? Why don't you just cut a little piece of leather to cover your feet?"

The king was surprised, but he later agreed to his suggestion, to make a "shoe" for himself.
There is actually a valuable lesson of life in this story : to make this world a happy place to live, you better change yourself - your heart; and not the world.

Monday, September 17, 2007

reCAPTCHA (f)or CAPTCHA


Are you human?

This is a question, many applications would ask on submitting a request to prevent automated attacks. You might've experienced entering distorted colorful text before the submission, that can be understood only by the human eye but by an automated bot. These are known as CAPTCHAs. It says that about 60 million CAPTCHAs are solved by humans around the world every day. This is millions of man-hrs wasted if you get the idea of re-CAPTCHA.

re-CAPTCHA will try to spend this effort in a useful way. Believe me, you are actually helping to digitize books. Instead of just typing some random text, which would be of no use to the mankind, you are digitizing a content of an old book, which appears a lil distorted as an image.
Interested? Pls continue...

And reCAPTCHA has a PHP library too.

Tuesday, September 11, 2007

How to export a private key from a java key store

This sample code shows how to export a private key from a Java Key store.

// Sample code taken from http://forum.java.sun.com/thread.jspa?threadID=154587&messageID=1403909
// How to export the private key from keystore?
// Does keytool not have an option to do so?
// This example use the "testkeys" file that comes with JSSE 1.0.3

*import* sun.misc.BASE64Encoder;
*import* java.security.cert.Certificate;
*import* java.security.*;
*import* java.io.File;
*import* java.io.FileInputStream;

*class* ExportPriv {
*public* *static* *void* main(String args[]) *throws* Exception{
ExportPriv myep = *new* ExportPriv();
myep.doit();
}

*public* *void* doit() *throws* Exception{

KeyStore ks = KeyStore.getInstance("JKS");
String fileName = "testkeys";

*char*[] passPhrase = "passphrase".toCharArray();
BASE64Encoder myB64 = *new* BASE64Encoder();
File certificateFile = *new* File(fileName);
ks.load(*new* FileInputStream(certificateFile), passPhrase);
KeyPair kp = getPrivateKey(ks, "duke", passPhrase);
PrivateKey privKey = kp.getPrivate();

String b64 = myB64.encode(privKey.getEncoded());

System.out.println("-----BEGIN PRIVATE KEY-----");
System.out.println(b64);
System.out.println("-----END PRIVATE KEY-----");
}

// From http://javaalmanac.com/egs/java.security/GetKeyFromKs.html

*public* KeyPair getPrivateKey(KeyStore keystore, String alias, *char*[] password) {
*try* {
// Get private key
Key key = keystore.getKey(alias, password);
*if* (key *instanceof* PrivateKey) {
// Get certificate of public key
Certificate cert = keystore.getCertificate(alias);
// Get public key
PublicKey publicKey = cert.getPublicKey();
// Return a key pair
*return* *new* KeyPair(publicKey, (PrivateKey)key);
}
} *catch* (UnrecoverableKeyException e) {
} *catch* (NoSuchAlgorithmException e) {
} *catch* (KeyStoreException e) {
}
*return* *null*;
}
}

Wednesday, September 05, 2007

WS-Policy 1.5 OUT!!!

W3C has release the version 1.5 of the Web Services Policy specification.
http://www.w3.org/TR/2007/REC-ws-policy-20070904/
WS-Policy Framework defines the behavior of a particular web service. It gives a set of assertions is specified in XML format. If interested in learning more about policy assertions click here.

Tuesday, September 04, 2007

Monday, September 03, 2007

Some Swedes can't go online...

Due to a bug in MS Vista, it said taht some Swedes can't go online.
http://www.theinquirer.net/default.aspx?article=42043

This has happened in the are of Lund, which belongs to the southern part of Sweden. Hmm... I wonder how they reacted to this... :)

DiggPicz

DigPicz to digg pics...
Check it out
http://digpicz.com/