These are my classes.... SwingChatServer wont compile cause of the error
"SwingChatServer.java:80: error: constructor DesEncrypter in class DesEncrypter cannot be applied to given types;
DesEncrypter encrypter = new DesEncrypter(key);
^
required: no arguments
found: SecretKey
reason: actual and formal argument lists differ in length
"
any ideas what this means lol xD I have been sitting here for hours getting all the issues out the way and then it craps on me with this error and I have no idea now... help??
Question
Original Poster
These are my classes.... SwingChatServer wont compile cause of the error
"SwingChatServer.java:80: error: constructor DesEncrypter in class DesEncrypter cannot be applied to given types;
DesEncrypter encrypter = new DesEncrypter(key);
^
required: no arguments
found: SecretKey
reason: actual and formal argument lists differ in length
"
any ideas what this means lol xD I have been sitting here for hours getting all the issues out the way and then it craps on me with this error and I have no idea now... help??
SwingChatServer.class
SwingChatGUI.class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SwingChatGUI extends JFrame
{
public JButton sendButton;
public JTextArea txArea, rxArea;
public Container container;
public SwingChatGUI (String title)
{
super (title);
container = getContentPane();
container.setLayout( new FlowLayout() );
txArea = new JTextArea (6, 40);
rxArea = new JTextArea (6, 40);
sendButton = new JButton ("Send");
container.add (rxArea);
container.add (txArea);
container.add (sendButton);
}
public static void main (String[] args)
{
Frame f = new SwingChatGUI ("Chat Program");
f.pack ();
f.setVisible(true);
}
}
[/CODE]
DesEncrypter.class
package chat;
import javax.crypto.*;
import java.security.spec.*;
import java.io.*;
public class DesEncrypter {
Cipher ecipher;
Cipher dcipher;
public void DesEncrypter(SecretKey key) {
try {
ecipher = Cipher.getInstance("DES");
dcipher = Cipher.getInstance("DES");
ecipher.init(Cipher.ENCRYPT_MODE, key);
dcipher.init(Cipher.DECRYPT_MODE, key);
} catch (javax.crypto.NoSuchPaddingException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} catch (java.security.InvalidKeyException e) {
}
}
public String encrypt(String str) {
try {
// Encode the string into bytes using utf-8
byte[] utf8 = str.getBytes("UTF8");
// Encrypt
byte[] enc = ecipher.doFinal(utf8);
// Encode bytes to base64 to get a string
return new sun.misc.BASE64Encoder().encode(enc);
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
}
return null;
}
public String decrypt(String str) {
try {
// Decode base64 to get bytes
byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
// Decrypt
byte[] utf8 = dcipher.doFinal(dec);
// Decode using utf-8
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (java.io.IOException e) {
}
return null;
}
}
[/CODE]
Link to comment
Share on other sites
2 answers to this question
Recommended Posts