• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception occurred during event dispatching

 
ian brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I've writtten an applet for secure registration, but unfortunatley i get these following errors upon input:
Exception occurred during event dispatching:
java.lang.NullPointerException
at PasswordEntry2.actionPerformed(Compiled Code)
at java.awt.Button.processActionEvent(Button.java:308)
at java.awt.Button.processEvent(Button.java:281)
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventQueue.dispatchEvent(Compiled Code)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)
it opens up the link fine but does none of my crypto stuff, i've pasted the file nad am sorry if it's very big, but i'm fairly new to applets and this forum.
import java.net.*;
import java.io.*;
import java.math.BigInteger;
import java.lang.Character.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class PasswordEntry2 extends Applet
implements ActionListener {
private TextField usernameField;
private TextField passwordField;
private TextField emailField;
private Button sendButton;
private TextArea resultsArea;
private TextField hostField;
private TextField portField,statusField, uriField;
private BigInteger gk,Pgak;
URL currentPage;
public void init() {
gk = new BigInteger("0");
Pgak = new BigInteger("0");
this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
usernameField = new TextField(20);
usernameField.addActionListener( this);

this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
passwordField = new TextField(20);
passwordField.setEchoChar( '*');
passwordField.addActionListener( this);
this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
emailField = new TextField(20);
emailField.addActionListener( this);
this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
statusField = new TextField(25);
statusField.setText("password status");
statusField.addActionListener( this);
sendButton = new Button("Submit Data");
sendButton.addActionListener(this);
String resultsMessage = " confirmation of registration will appear here deedum";
resultsArea = new TextArea();
resultsArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
resultsArea.setText(resultsMessage);

this.add( usernameField);
this.add( passwordField);
this.add( emailField);
this.add(statusField);
this.add(sendButton);
} // End init.

public void actionPerformed(ActionEvent event) {
try {
URL userUrl = new URL("http://www.google.com");
getAppletContext().showDocument(userUrl,"_blank");
}
catch (Exception e) {
System.out.println(" Something happened with the web page opening ");
}

try {
// here are the connection parameters
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
String uri = "/cgi-bin/receive.pl";
String portString = String.valueOf(currentPage.getPort());
int port;
try {
port = Integer.parseInt(portString);
}
catch(NumberFormatException nfe) {
port = -1; // I.e., default port of 80
}
// Here we must encrypt the password to get the ElGamal numbers
//String password = passwordField.getTextField().getText();
String password = passwordField.getText();
System.out.println(password);
Elencrypt(password);
System.out.println( "past Elencrypt Pgak value in "+Pgak.toString());
System.out.println( "encoded version is " +URLEncoder.encode(Pgak.toString()) );
// NB this has set the values of gk and Pgak
URL dataURL = new URL(protocol, host, port, uri);
URLConnection connection = dataURL.openConnection();
// Make sure browser doesn't cache this URL.
connection.setUseCaches(false);
// Tell browser to allow me to send data to server.
connection.setDoOutput(true);
ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(512); // Grows if necessary
// Stream that writes into buffer
PrintWriter out = new PrintWriter(byteStream, true);
System.out.println(" the parameter value of gk is "+URLEncoder.encode(gk.toString()) );
System.out.println(" the parameter value of Pgak is "+URLEncoder.encode(Pgak.toString()) );
String postData =
"userName=" + encodedValue(usernameField) +
"&gk=" + URLEncoder.encode(gk.toString()) +
"&Pgak=" + URLEncoder.encode(Pgak.toString()) +
"&emailAddress=" + encodedValue(emailField);
statusField.setText( "setting up parameters");
// Write POST data into local buffer
out.print(postData);
out.flush(); // Flush since above used print, not println
// POST requests are required to have Content-Length
String lengthString =
String.valueOf(byteStream.size());
connection.setRequestProperty
("Content-Length", lengthString);
// Netscape sets the Content-Type to multipart/form-data
// by default. So, if you want to send regular form data,
// you need to set it to
// application/x-www-form-urlencoded, which is the
// default for Internet Explorer. If you send
// serialized POST data with an ObjectOutputStream,
// the Content-Type is irrelevant, so you could
// omit this step.
connection.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
// Write POST data to real output stream
byteStream.writeTo(connection.getOutputStream());
// let them know the passwords been sent
statusField.setText( "checking for server acknowledgement");
/* now we should confirm that the password has been successfully stored
We must snd something back form the perl script to this effect
The input Buffer willl pick it up and display it in the
Status field for us
*/
//System.out.println( "about to set up input stream reader");
BufferedReader in =
new BufferedReader(new InputStreamReader
(connection.getInputStream()));
//System.out.println( "past input stream reader");
String line;
String linefeed = "\n";
//resultsArea.setText("");
statusField.setText( "");
while((line = in.readLine()) != null) {
statusField.setText(line);
//resultsArea.append(line);
// resultsArea.append(linefeed);
}
} catch(IOException ioe) {
// Print debug info in Java Console
System.out.println("IOException: " + ioe);
}
statusField.setText("Password sent");
}


private String encodedValue(TextField field) {
String rawValue = field.getText();
return(URLEncoder.encode(rawValue));
}

private void Elencrypt(String password)
{
/* let's set up the two values gk and Pgak here
They are private members so are accessible from the method
*/
// Firstly our encryption data
BigInteger g = new BigInteger("3");
BigInteger ga = new BigInteger("27");
BigInteger n = new BigInteger("1331656851383141126634824735487135481");
BigInteger k = new BigInteger("2");
// ******************* to be changed to random *****************
BigInteger gak = new BigInteger("0");
BigInteger P = new BigInteger("0");
gk=g.modPow(k,n);
gak=ga.modPow(k,n);
P=toNumber(password);
System.out.println( " P value in encrypt is "+P);
Pgak=P.multiply(gak);
System.out.println( " Pgak value in encrypt is "+Pgak);
}
private BigInteger toNumber(String phrase)
{
/*
toNumber encodes a phrase to its number equivalent
Constraints: phrase should be at most 10 characters
This needs to corrspond with the undo on the server
*/
// Step 1 String to char array
int phraseLength = phrase.length();
char[] charArray = phrase.toCharArray();
// Step2 phrase to num equiv array eg tom -> 14,23,12
int count=0;
BigInteger P = new BigInteger("0");
BigInteger base = new BigInteger("256");
BigInteger basePow = new BigInteger("1");
BigInteger BigNumEquiv = new BigInteger("1");
int asciival = 0;
while(count<phraseLength)
{
asciival=(int)charArray[count]; // determines the ascii value of a char
BigNumEquiv = new BigInteger(""+asciival); // changes int to String
System.out.println( " ascii value is "+BigNumEquiv);
P=P.add(BigNumEquiv.multiply(basePow));
basePow=basePow.multiply(base);
count++;
}
return P;
}
} // end class PasswordEntry.
thanks for any help
adunkey
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were to surround the code with the [code] and [/code] UBB tags, then any formatting would be preserved and the code would be easier to follow. Note that you can edit your own post by clicking on the icon that looks like a piece of paper with a pencil - you don't have to repost your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic