String data;
data = "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.";
try {
FileOutputStream fos = new FileOutputStream("test");
ObjectOutputStream oos = new ObjectOutputStream(fos);
// In 1.2 beta 4, the following method requires an argument
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
// In 1.2 beta 4, the getKey and load methods have a new signature
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);
PrivateKey pk = (PrivateKey) ks.getKey(args[0], c);
Signature s = Signature.getInstance("DSA");
s.initSign(pk);
byte buf[] = data.getBytes();
s.update(buf);
oos.writeObject(data);
oos.writeObject(s.sign());
} catch (Exception e) {
e.printStackTrace();
}