package org.avis.client.examples;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.avis.client.Elvin;
import org.avis.client.Notification;
import org.avis.security.Key;
import org.avis.security.Keys;
import static org.avis.client.SecureMode.REQUIRE_SECURE_DELIVERY;
import static org.avis.security.KeyScheme.SHA1_CONSUMER;
public class SecureSender
{
public static void main (String [] args)
throws Exception
{
Elvin elvin =
new Elvin (System.getProperty ("elvin", "elvin://localhost"));
elvin.closeOnExit ();
BufferedReader stdin =
new BufferedReader (new InputStreamReader (System.in));
System.out.println ("Enter the password for sending: ");
String password = stdin.readLine ();
System.out.println ("Enter the text to send: ");
String message = stdin.readLine ();
Notification secretMessage = new Notification ();
secretMessage.set ("From", "secure-sender");
secretMessage.set ("Message", message);
Key privateKey = new Key (password);
Keys sendingKeys = new Keys ();
sendingKeys.add (SHA1_CONSUMER, privateKey.publicKeyFor (SHA1_CONSUMER));
elvin.send (secretMessage, sendingKeys, REQUIRE_SECURE_DELIVERY);
System.out.println ("Message sent!");
elvin.close ();
}
}