FileDocCategorySizeDatePackage
Receive.javaAPI DocExample1104Sun Jan 14 22:20:24 GMT 2001javasec.samples.ch13

Receive

public class Receive extends Object

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

        try {
            ObjectInputStream ois = new ObjectInputStream(
                        new FileInputStream("keyfile"));
            DESKeySpec ks = new DESKeySpec((byte[]) ois.readObject());
            SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
            SecretKey key = skf.generateSecret(ks);

            Cipher c = Cipher.getInstance("DES/CFB8/NoPadding");
            c.init(Cipher.DECRYPT_MODE, key, 
                   new IvParameterSpec((byte[]) ois.readObject()));
            CipherInputStream cis = new CipherInputStream(
                        new FileInputStream("ciphertext"), c);
            BufferedReader br = new BufferedReader(
                        new InputStreamReader(cis));
            System.out.println("Got message");
            System.out.println(br.readLine());
        } catch (Exception e) {
            System.out.println(e);
        }