FileDocCategorySizeDatePackage
ReceiveObject.javaAPI DocExample3676Sat Jan 13 14:28:26 GMT 2001javasec.samples.ch12

ReceiveObject

public class ReceiveObject extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        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();
        }
    
private static voidprocessCertificate(java.security.cert.X509Certificate x509)

        Principal p;
        p = x509.getSubjectDN();
        System.out.println("This message was signed by " +
                            p.getName());
        p = x509.getIssuerDN();
        System.out.println("This certificate was provided by " +
                            p.getName());
        try {
            verifySigner(x509, p.getName());
        } catch (CertificateException ce) {
            System.out.println("We don