FileDocCategorySizeDatePackage
ReceiveXYZ.javaAPI DocExample1273Sat Jan 13 14:15:38 GMT 2001javasec.samples.ch11

ReceiveXYZ

public class ReceiveXYZ extends Object

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

        try {
            FileInputStream fis = new FileInputStream("test.xyz");
            ObjectInputStream ois = new ObjectInputStream(fis);
            Object o = ois.readObject();
            if (!(o instanceof String)) {
                System.out.println("Unexpected data in file");
                System.exit(-1);
            }
            String data = (String) o;
            System.out.println("Got message " + data);
            o = ois.readObject();
            if (!(o instanceof byte[])) {
                System.out.println("Unexpected data in file");
                System.exit(-1);
            }
            byte origDigest[] = (byte []) o;
            Security.addProvider(new XYZProvider());
            MessageDigest md = MessageDigest.getInstance("XYZ");
            md.update(data.getBytes());
            if (MessageDigest.isEqual(md.digest(), origDigest))
                System.out.println("Message is valid");
            else System.out.println("Message was corrupted");
        } catch (Exception e) {
            System.out.println(e);
        }