try {
FileOutputStream fos = new FileOutputStream("test.obj");
ObjectOutputStream oos = new ObjectOutputStream(fos);
// In 1.2 beta 4, these methods have all changed signature
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
char c[] = new char[args[1].length()];
args[1].getChars(0, c.length, c, 0);
ks.load(new FileInputStream(System.getProperty("user.home") + File.separator + ".keystore"), c);
java.security.cert.Certificate certs[] = ks.getCertificateChain(args[0]);
PrivateKey pk = (PrivateKey) ks.getKey(args[0], c);
Message m = new Message();
m.object = new SignedObject(
"This have I thought good to deliver thee, " +
"that thou mightst not lose the dues of rejoicing " +
"by being ignorant of what greatness is promised thee.",
pk, Signature.getInstance("DSA"));
m.certificate = certs[0];
oos.writeObject(m);
} catch (Exception e) {
System.out.println(e);
}