try {
FileInputStream fis = new FileInputStream("test.obj");
ObjectInputStream ois = new ObjectInputStream(fis);
Object o = ois.readObject();
if (o instanceof Message) {
Message m = (Message) o;
System.out.println("Received message");
processCertificate((X509Certificate) m.certificate);
PublicKey pk = m.certificate.getPublicKey();
if (m.object.verify(pk, Signature.getInstance("MD5withRSA"))) {
System.out.println("Message is valid");
System.out.println(m.object.getObject());
}
else System.out.println("Message signature is invalid");
}
else System.out.println("Message is corrupted");
} catch (Exception e) {
e.printStackTrace();
}