Simple encryption applet
I'm just wondering if somewhere on the web there was any site with the ability to simply input a String, and a salt, and have it encrypt it, or enter a String (encrypted) and the salt used and have it decrypt it. I put applet in the title, but I don't even care if it's in java. I could probably write one myself but first of all I don't want to re-invent the wheel, and second of all I don't want anyone thinking I messed with the program to steal passwords. Thanks.
Also think of ways of dealing with salt. Typically, it is unwise to use the same encryption key for large volumes of data. One way to somewhat minimize this is for the server to generate a token (salt) and send it to the client. The client uses this token as the salt for the PBE based authentication encryption as well as the encrypted content. The server would send a new token (salt) to the client until the authentication is successful. Once the authentication is successful the token used during authentication (salt) is used until the session is complete or timed out. Thus every time a user comes to your site his/her session key (aka the key derived by PBE using the salt and password) would be different.
It would also eliminate possible dictionary attacks against your system....
Similar Messages
-
Hey i am trying to create a simple encryption. This is my function.
public static String Crypt(String sData)
byte[] bytes = sData.getBytes();
for(int i=0; i<bytes.length; i++)
bytes[i] ^= 477;
return (new String(bytes));
Unfortunately the String that is returned has a lot of "???????" in it. I have also tried char arrays but to no effect. I want to be able to send the data using a socket therefore i need it in a char array or string. Can anyone help please?>
return (new String(bytes));
Unfortunately the String that is returned has a lot of
"???????" in it. I have also tried char arrays but to
no effect. I want to be able to send the data using a
socket therefore i need it in a char array or string.1) Not all byte and byte combinations produce a valid String object so one cannot use 'new String(bytes)' with the certainty of being able to reverse the operation and get back the original bytes. i.e.
new String(some bytes).getBytes() usually does not return 'some bytes'.
2) You don't need to have a char array or string to send bytes down a Socket. Just send down the encrypted bytes.
3) I hope you are not considering this encryption method for an industrial strength application! -
Hi there,
Where can i find a very simple encryption algorithm to allow me to encrypt basic strings?
It should be simple enough so i can make a version for Java and Cobol.
Thanks for any help.I guess you can implement any encryption algorithm with either language. XOR should suffice... just not ROT13, it'll be a pain with EBCDIC. XOR each byte with some byte you randomly picked.
-
ok, i'm working on a project involving buttons, and i finished it and it compiles fine, but when i run the applet (using textpad), nothign shows up.
i decided to make a new applet of only the frame and buttons, and i got the same problem. here is the simple one.
import java.util.*;
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class framek extends JApplet
public static final int WIDTH = 600;
public static final int HEIGHT = 300;
public void framek()
JFrame myWindow = new JFrame();
myWindow.setSize(WIDTH, HEIGHT);
Container contentPane = myWindow.getContentPane();
contentPane.setBackground(Color.blue);
contentPane.setLayout(new BorderLayout());
JPanel button = new JPanel();
button.setLayout(new FlowLayout());
JButton convert = new JButton("Translate");
button.add(convert);
JButton delete = new JButton("Delete");
button.add(delete);
contentPane.add(button, BorderLayout.SOUTH);
i might have made some mistakes in the shortening of my project (such as variables that arent used) but i just need help with getting the buttons and background things to show. I used very similar programs in a textbook and on the web to check and they worked fine on textpad, and this doesnt. its probably a very simple thing that i forgot but i cant find it yet, as i am fairly new to swing.
any help is appreciated thanks/* <applet code="HelloApplet" width="600" height="300"></applet>
* use: >appletviewer HelloApplet.java
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class HelloApplet extends JApplet
public static final int WIDTH = 600;
public static final int HEIGHT = 300;
public void init()
Container contentPane = getContentPane();
contentPane.setBackground(Color.blue);
contentPane.setLayout(new BorderLayout());
JPanel button = new JPanel();
button.setLayout(new FlowLayout());
JButton convert = new JButton("Translate");
button.add(convert);
JButton delete = new JButton("Delete");
button.add(delete);
contentPane.add(button, BorderLayout.SOUTH);
/** this is a convenience method */
public static void main(String[] args)
JApplet applet = new HelloApplet();
JFrame myWindow = new JFrame();
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.add(applet);
myWindow.setSize(WIDTH, HEIGHT);
myWindow.setLocation(200,200);
applet.init();
myWindow.setVisible(true);
} -
Simple Encryption and Simple Question
Anyway, I hope it is simple!
This is from an example in my text book, I have coded it up and it works great. I think I understand everything except for the subtraction of 'A' in the encryptMessage method. Any ideas? I thought it may be subtracting the ASCII value of 'A', but isn't that just 1?
Any help is appreciated.
public class CeasarCryptography
public static final int ALPHASIZE = 26; //Standard English alphabet size, ALL uppercase
public static char[] alpha = {'A','C','B','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
protected char[] encryptionKey = new char[ALPHASIZE];
protected char[] decryptionKey = new char[ALPHASIZE];
public CeasarCryptography()
//Initializes encryptionArray
for (int x = 0; x < encryptionKey.length; x++)
encryptionKey[x] = alpha[ (x + 3) % ALPHASIZE ]; //Rotate alphabet by three places
//Initializes encryptionArray and decryptionArray
for (int x = 0; x < decryptionKey.length; x++)
decryptionKey[encryptionKey[x] - 'A'] = alpha[x]; //Decypt is revers of encrypt
public String encryptMessage(String secret)
char[] mess = secret.toCharArray(); //First, place the string in an array
for (int x = 0; x < mess.length; x++)
if (Character.isUpperCase(mess[x]))
mess[x] = encryptionKey[mess[x] - 'A'];
return new String(mess);
public String decryptMessage(String secret)
char[] mess = secret.toCharArray();
for (int x = 0; x < mess.length; x++)
if (Character.isUpperCase(mess[x]))
mess[x] = decryptionKey[mess[x] - 'A'];
return new String(mess);
public static void main(String[] args)
CeasarCryptography cipherObject = new CeasarCryptography();
System.out.println("Welcome to the oldest known enryption program.");
System.out.println("\tEncryption Key: " + new String(cipherObject.encryptionKey));
System.out.println("\tDecryption Key: " + new String(cipherObject.decryptionKey));
String testString = "JAVA IS NOT EASY";
System.out.println("\nEncrypt the following: " + testString);
System.out.println("\tOnce encrypted: " + cipherObject.decryptMessage(testString));
}If the value of 'A' is not important, how is 'D' -
'A' 3? Because D is 3 later than A. So whether 'A' is -123 or 0 or 1 or 65, 'A' + 3 is always 'D'.
Or is this D (which is the 4th letter) minus A
(which is the 1st letter) for 4-1 = 3. Right. It's just that in ASCII, 'A' is 65, instead of 1 or 0 that we usually think of it. The whole minus 'A' part is just to say "how far away from A are we, and therfore how much are we shifting?"
And 3 is the
element in the Array that D is in?I was winging it here but that's what it comes down to. Whether it's an index into an array where 'A' is in 0, 'B' is in '1', etc., or just an on-the-fly shifting, either way, "minus 'A'" ultimately means "How far away from A is this letter?" -
Searching for simple upload applet
I hope this is the right forum for this query
I need an "upload any size file" applet. Most of the commercial ones are way overblown in features that you can't turn off. All I need is the ability to upload a file of any size, browse for the file to upload, and pass parameters with each file.
are there any simple applets like that available?
thanks for you time and thoughts
--- ericHa ha.
How about telling us what's supposed to accept the
upload? Technically, simple HTML is sufficient. The
other end of the line defines what you need.sorry for the new id, the forum lost my old one.
well the code I've seen elsewhere dictated a server side solution for me. ;-)
my expectation? since browsers fail to upload more than 90mb at a time (give or take), I expect that the file would be uploaded in chunks or slices. I expect to write a cgi program that would stich together those chunks based on cgi parameters uploaded with the file chunk.
another alternative for the applet is to stream the file to a file transfer server server with authentication via server generated auth tokens. Or something...
and no, ssh/ftp and the like are not acceptable for a varity of reasons unless I can write anon write only and can tell the server side app when the xfr is done.
thanks -
Creating a SIMPLE Java APPLET for a HTML website
Hello!
I was wondering if anyone can help me.
i have designed a very simple HTML website and wanted to make an applet.
which program would be best (eclipse, blue j...etc)
and how do i go about it!
i am very new to this and would appriciate the help
many thanks in advancesabre150 wrote:
gimbal2 wrote:
your brain to do all the hard work. It needs to be preloaded with knowledge of programming, the Java language, the Java platform and the Java plugin relating to applets before it will work.So that's where I have been going wrong!Lies, I know for a fact that you know a thing or two. What are you trying to do here? Hide from your responsibilities as a knowledgeable person? -
Problems deploying a simple Infobus Applet
Hi,
I am testing the infrastructure required to build an Infobus
Applet for our Web-based application using the Business Component
Framework in JDeveloper 3.0.
I have created a simple project based on the Scott schema, which
uses the Java Business Object framework to define Entity Objects,
Views, etc. for the Dept and Emp tables.
I have then created, using the Wizard, an Infobus Data Form to
create a master-detail Applet to display Employees within a
Department based on the above mentioned View Object. This works
fine when running within JDeveloper3.
However, when I try to deploy the applet to our Oracle
Application Server as a simple HTML file and JAR file (not using
EJB, etc. as we currently only have OAS 4.0.7.1 - waiting for OAS
4.0.8 to be available for download), the applet fails to start.
I have installed the Java Plug-in 1.2.2 from Sun as documented as
I'm using Swing controls.
After much frustration with the online 'Help', I managed to
create a deployment profile which included the appropriate
archives (See Packaging Source and Deployment Files in Help -
still refers to 'Rules' and 'Sources' pages ala JDeveloper 2 NOT
3.0).
Using the Console feature of the Java Plug-in, I was able to see
the progress of the Applets classes being loaded. It gets to the
point where it's trying to load the ResTable classes in
dacf.zip as found in the path:
oracle\dacf\control\swing\find
At this point, it just stops and nothing else happens.
Do I need to explicitly localize my Infobus Applet because I'm in
the United Kingdom and my PC has that as it's Regional Setting?
That is, do I need to define a ResTable_en_GB version of this
class?
Also, in attempting to create a localized version, I had errors
with JDeveloper stating that the text for the FIND_HELP_MESSAGE
exceeds the limit of JDeveloper (meaning that it's too long and I
needed to replace it with a shorter string). Could this be the
problem in the first place?
I have not been able to get the Applet to get beyond this point,
although I'm still trying the localization to Great Britain.
I know this is already a LONG email, but here is an extract from
the Java Console after which nothing else happens:
CacheHandler file name: null
Opening
http://dell_server.wsp.co.uk:4005/oracle/dacf/control/swing/find/
ResTable_en.properties no proxy
Opening
http://dell_server.wsp.co.uk:4005/oracle/dacf/control/swing/find/
ResTable_en.properties with cookie
"SITESERVER=ID=8e93834f82ef0710b78e5a4b087d6eed".
Regards
Gene Schneider
nullParameter passing in EJB must implement Serializable. One way to solve this is:
1. Define a new class which implements
Serializable.
2. Place whatever you want to pass inside
this class.
3. Now use the new class as your parameter.
eg.
public class Params implements java.io.Serializable {
String p1;
XmlDocmuent xdoc;,
etc, etc
Your program now have to use the class Params for parameter passing.
Hope this helps.
Tam
null -
im following the java tutorial at their web site online. I'm having problems with these simple applets:
http://java.sun.com/docs/books/tuto...kMeApplets.html
I compiled them fine on my other computer, but when I compiled them on the computer I am using presently, I get a problem.
the files seem to compile fine. but when i compare them with the files online, my files that i compiled are a little less in size. when i load the applet in the provided html file, all i get is a blank gray screen. and when i move the mouse over the gray screen, it says for a split second: "load: class ClickMe not found"
i have all the correct files...but after compiling the .java files, it doesn't work. the .class files on the web work fine. but my compiled files seem to be smaller than those on the web.
the ClickMe.class file i compiled is 1.45 KB (1,494 bytes)
the Spot.class file i compiled is 293 bytes (293 bytes)
the ClickMe.class file online is 1.50 KB (1,539 bytes)
the Spot.class file online is 339 bytes (339 bytes)I believe that one (or more) of these applats are currently broken - the files are mislocated, I believe. Just skip the clickme applets (unless you want to debug them yourself).
-
Getting addActionEvent listener to work for Simple Button Applet
Hi, im trying to get some simple code running in this little button applet but im having a hard time trying to get NetBeans to allow me to do it. The Code is as follows:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Clickers extends Applet
TextField text1;
Button button1, button2;
public void init()
text1 = new TextField(20);
add(text1);
button1 = new Button("Welcome To");
add(button1);
button1.addActionListener(this);
button2 = new Button("Java");
add(button2);
button2.addActionListener(this);
public void actionPerformed(ActionEvent e)
if (e.getSource() == button1)
text1.setText("Welcome To");
if (e.getSource() == button2)
text1.setText("Java");
upon compiling i get the error:
addActionListener(java.awt.event.ActionListener) in java.awt.Button cannot be applied to (Clickers)
for both the buttons.
can someone explain why???
Thanks
Richard.Its ok just realised didnt implement ActionListener
-
Hi All, I want to encrypt a simple text as given in the example below BUT I am getting 'java.lang.NoSuchMethodError' Exception at the Cipher.getInstance("DES") method.
Please help me or give me some references.
Write me at [email protected]
This is the test code -
Cipher desCipher;
byte[] desKeyData = { (byte)0x01, (byte)0x02, (byte)0x03,..};
SecretKeySpec desKey = new SecretKeySpec(desKeyData, "DES");
// Getting Exception at this point
desCipher = Cipher.getInstance("DES");
desCipher.init(Cipher.ENCRYPT_MODE, desKey);
// Our cleartext
byte[] cleartext = "This is just an example".getBytes();
// Encrypt the cleartext
byte[] ciphertext = desCipher.doFinal(cleartext);
// Initialize the same cipher for decryption
desCipher.init(Cipher.DECRYPT_MODE, desKey);
// Decrypt the ciphertext
byte[] cleartext1 = desCipher.doFinal(ciphertext);try this:
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SealedObject;
import java.security.*;
import java.io.*;
import javax.crypto.*;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.KeyAgreement;
import javax.swing.*;
public class encryptTest
public static void main(String args[])
String password = JOptionPane.showInputDialog(null,"Plz Enter Any word to Encrypt");
Security.addProvider(new com.sun.crypto.provider.SunJCE());
try
KeyGenerator kg = KeyGenerator.getInstance("DES");
Key key = kg.generateKey();
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE,key);
byte[] encrypted_password = cipher.doFinal(password.getBytes());
JOptionPane.showMessageDialog(null,"Encrypted Password "+ new String(encrypted_password));
cipher.init(Cipher.DECRYPT_MODE,key);
byte[] decrypted_password = cipher.doFinal(encrypted_password);
JOptionPane.showMessageDialog(null,"Decrypted Password "+new String(decrypted_password));
catch(NoSuchAlgorithmException nsae)
System.out.println("No Such Algorithm Exception " + nsae.getMessage());
catch(NoSuchPaddingException nspe)
System.out.println("No Such Padding Exception " + nspe.getMessage());
catch(InvalidKeyException ike)
System.out.println("Invalid Key Exception " + ike.getMessage());
catch(IllegalStateException ise)
System.out.println("Illegal State Exception " + ise.getMessage());
catch(IllegalBlockSizeException ibse)
System.out.println("Illegal Block Size Exception " + ibse.getMessage());
catch(BadPaddingException bpe)
System.out.println("Bad Padding Exception " + bpe.getMessage()); -
i have a very simple user authentication system, where user info is stored in a flat text file on the server. I want to encrypt the password so that it's not stored in plain text, but I can't understand any of the tutorials about security and encryption...is there any way that I can just use a class (or a few) to encrypt the password in the file, then encrypt submitted passwords & check if they match (rather than dealing wiht public and private keys and all that jazz)
thanks a lot
LazInstead of encrypting the password you should calculate message digest (i.e. MD5 or SHA).
java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA");
md.update( password.getBytes());
byte[] digest = md.digest(); -
Making a simple calc applet. Where am I going wrong?
Hi everyone. I'm taking a introductory java class over the summer and so far I've been doing pretty good in it. I've been able to knock out and figure out how to do most of the assignments on my own. But this latest problem is driving me up a wall. I think I might be making it more difficult then it is. I'm supposed to a take a simple calculation program, and then convert it into an applet with new button functionality and text fields. In the applet, there will be two text fields(input and result) and two buttons(Update and Reset). In the first field you put in an operator and a number. Then from there you hit the Update button and the new value is put in the second field.
For example. The program is defaulted to "0". So you put "+ 9" in the first field, then Hit Update. "9" will now appear in the second field. Go back to the first field and put in "- 3", hit update again and now the second field will go to "6." You can keep doing this all you want. Then when you want to start all over again you hit reset. Its sort of a weird program.
Here's the original calc program:
import java.util.Scanner;
Simple line-oriented calculator program. The class
can also be used to create other calculator programs.
public class Calculator
private double result;
private double precision = 0.0001; // Numbers this close to zero are
// treated as if equal to zero.
public static void main(String[] args)
Calculator clerk = new Calculator( );
try
System.out.println("Calculator is on.");
System.out.print("Format of each line: ");
System.out.println("operator space number");
System.out.println("For example: + 3");
System.out.println("To end, enter the letter e.");
clerk.doCalculation();
catch(UnknownOpException e)
clerk.handleUnknownOpException(e);
catch(DivideByZeroException e)
clerk.handleDivideByZeroException(e);
System.out.println("The final result is " +
clerk.getResult( ));
System.out.println("Calculator program ending.");
public Calculator( )
result = 0;
public void reset( )
result = 0;
public void setResult(double newResult)
result = newResult;
public double getResult( )
return result;
The heart of a calculator. This does not give
instructions. Input errors throw exceptions.
public void doCalculation( ) throws DivideByZeroException,
UnknownOpException
Scanner keyboard = new Scanner(System.in);
boolean done = false;
result = 0;
System.out.println("result = " + result);
while (!done)
char nextOp = (keyboard.next( )).charAt(0);
if ((nextOp == 'e') || (nextOp == 'E'))
done = true;
else
double nextNumber = keyboard.nextDouble( );
result = evaluate(nextOp, result, nextNumber);
System.out.println("result " + nextOp + " " +
nextNumber + " = " + result);
System.out.println("updated result = " + result);
Returns n1 op n2, provided op is one of '+', '-', '*',or '/'.
Any other value of op throws UnknownOpException.
public double evaluate(char op, double n1, double n2)
throws DivideByZeroException, UnknownOpException
double answer;
switch (op)
case '+':
answer = n1 + n2;
break;
case '-':
answer = n1 - n2;
break;
case '*':
answer = n1 * n2;
break;
case '/':
if ((-precision < n2) && (n2 < precision))
throw new DivideByZeroException( );
answer = n1 / n2;
break;
default:
throw new UnknownOpException(op);
return answer;
public void handleDivideByZeroException(DivideByZeroException e)
System.out.println("Dividing by zero.");
System.out.println("Program aborted");
System.exit(0);
public void handleUnknownOpException(UnknownOpException e)
System.out.println(e.getMessage( ));
System.out.println("Try again from the beginning:");
try
System.out.print("Format of each line: ");
System.out.println("operator number");
System.out.println("For example: + 3");
System.out.println("To end, enter the letter e.");
doCalculation( );
catch(UnknownOpException e2)
System.out.println(e2.getMessage( ));
System.out.println("Try again at some other time.");
System.out.println("Program ending.");
System.exit(0);
catch(DivideByZeroException e3)
handleDivideByZeroException(e3);
}Here's me trying to make it into an applet with the added button functionality.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Calculator extends JApplet implements ActionListener
// Variables declaration.
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField2;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JTextArea resultArea;
private Container container;
// End of variables declaration
public void init () {
initComponents();
setSize(400, 200);
private void initComponents() {
container = getContentPane();
container.setLayout( new BorderLayout() );
// Creating instances of each item
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
resultArea = new javax.swing.JTextArea();
// End Creation
// Set text on labels, preferred size can be optional on labels,
// size should/must be used on text fields.
// Then each individual item is added to a panel.
jLabel2.setText("Input =");
jPanel2.add(jLabel2);
jTextField1.setText("");
jTextField1.setPreferredSize(new java.awt.Dimension(65, 20));
jPanel2.add(jTextField1);
container.add( jPanel2, BorderLayout.SOUTH);
jButton1.setText("Update");
jButton1.addActionListener(this);
jButton2.setText("Reset");
jButton2.addActionListener(this);
container.add(resultArea, BorderLayout.CENTER);
container.add(jButton1, BorderLayout.WEST);
container.add(jButton2, BorderLayout.EAST);
resultArea.setText("Calculator is on.\n" +
"Format of each line: " +
"\noperator space number" +
"\nFor example: + 3" +
"\nThen hit Update to compute"+
"\nHit Reset to set the result back to zero.");
private double result;
private double precision = 0.0001;
public void actionPerformed(ActionEvent e)
Calculator clerk = new Calculator( );
try
clerk.doCalculation();
catch(UnknownOpException e2)
clerk.handleUnknownOpException(e2);
catch(DivideByZeroException e2)
clerk.handleDivideByZeroException(e2);
resultArea.setText("The final result is " + clerk.getResult( )+
"\nCalculator program ending.");
public Calculator( )
result = 0;
public void reset( )
result = 0;
public void setResult(double newResult)
result = newResult;
public double getResult( )
return result;
The heart of a calculator. This does not give
instructions. Input errors throw exceptions.
public void doCalculation( ) throws DivideByZeroException,
UnknownOpException
Scanner keyboard = new Scanner(System.in);
boolean done = false;
result = 0;
resultArea.setText("result = " + result);
while (!done)
char nextOp = (keyboard.next( )).charAt(0);
if ((nextOp == 'e') || (nextOp == 'E'))
done = true;
else
double nextNumber = keyboard.nextDouble( );
result = evaluate(nextOp, result, nextNumber);
resultArea.setText("result " + nextOp + " " + nextNumber + " = " + result+
"\nupdated result = " + result);
Returns n1 op n2, provided op is one of '+', '-', '*',or '/'.
Any other value of op throws UnknownOpException.
public double evaluate(char op, double n1, double n2)
throws DivideByZeroException, UnknownOpException
double answer;
switch (op)
case '+':
answer = n1 + n2;
break;
case '-':
answer = n1 - n2;
break;
case '*':
answer = n1 * n2;
break;
case '/':
if ((-precision < n2) && (n2 < precision))
throw new DivideByZeroException( );
answer = n1 / n2;
break;
default:
throw new UnknownOpException(op);
return answer;
public void handleDivideByZeroException(DivideByZeroException e)
resultArea.setText("Dividing by zero."+
"\nProgram aborted");
System.exit(0);
public void handleUnknownOpException(UnknownOpException e)
resultArea.setText(e.getMessage( )+
"\nTry again from the beginning:");
try
resultArea.setText("Calculator is on.\n" +
"Format of each line: " +
"\noperator space number" +
"\nFor example: + 3" +
"\nHit Reset to set the result back to zero.");
doCalculation( );
catch(UnknownOpException e2)
System.out.println(e2.getMessage( ));
System.out.println("Try again at some other time.");
System.out.println("Program ending.");
System.exit(0);
catch(DivideByZeroException e3)
handleDivideByZeroException(e3);
}I'm not getting any compiling errors or anything and it launches, but it doesn't work at all. I'm sure it has something to do with the calc program and the applet actionevent. I just don't know where to go from there. Can anyone tell me where I'm going wrong? Or even make sense of what I've posted. I know its a lot. I've been looking at this thing for a day now and its killing me. Any help would be greatly appreciated. Thanks.This is a mistake
public void actionPerformed(ActionEvent e)
Calculator clerk = new Calculator( );
try
clerk.doCalculation();You don't want to create a whole new applet every time anyone pushes a button.
Make whatever changes are neccessary so that you don't have to create a new applet in your actionPerformed -
Simple encryption... need help...
hello friends,
this may be a simple problem, but, as i m new plz forgive me...
i have to accept three command line agrumetns like...
name ---> string
age ---> integer
date ---> string
now, i want to encrypt these data in a two different text files with two different encryption methods...
and later i need to decrypt the data from both the textfiles...
can anyone help me how can i achieve this task ???
Thanks,
Rohanhi arshad,
thanks for the guidence...
i just needed the proper direction... not the code...
Thanks again...
i went through some books and tried a sample code from a book...
here is the code...
package des;
import java.io.*;
import java.security.*;
import javax.crypto.*;
import sun.misc.*;
* @author Rohan.Nakar
public class SecretWriting
public static void main(String[] args) throws Exception
//checking argumetns
if(args.length < 2)
System.out.println("Usage: SecureWriting -e | -d plainText");
return;
//get or create key
Key key;
try
ObjectInputStream in = new ObjectInputStream( new FileInputStream("SecretKey.ser"));
key = (Key)in.readObject();
in.close();
catch (FileNotFoundException fnfe)
KeyGenerator generator = KeyGenerator.getInstance("DES");
generator.init(new SecureRandom());
key = generator.generateKey();
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("SecretKey.ser"));
out.writeObject(key);
out.close();
//get a cipher object
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
//Encrypt or decrypt the input string
if (args[0].indexOf("e") != -1)
cipher.init(Cipher.ENCRYPT_MODE, key);
String amalgam = args[1];
for(int i = 2; i < args.length; i++)
amalgam += " " + args;
byte[] stringBytes = amalgam.getBytes("UTF8");
byte[] raw = cipher.doFinal(stringBytes);
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(raw);
System.out.println(base64);
else if (args[0].indexOf("d") != -1)
cipher.init(Cipher.DECRYPT_MODE, key);
BASE64Decoder decoder = new BASE64Decoder();
byte[] raw = decoder.decodeBuffer(args[1]);
byte[] stringBytes = cipher.doFinal(raw);
String result = new String(stringBytes, "UTF8");
System.out.println(result);
this is giving me an exception...
java.security.NoSuchAlgorithmException: Algorithm DES not available
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.KeyGenerator.getInstance(DashoA6275)
at des.SecretWriting.main(SecretWriting.java:40)
Exception in thread "main"
any help...
Thanks in advance... -
Simple java applet help needed
hi, im having trouble with an applet im developing for a project.
i have developed an applet with asks the user for simple information( name,address and phone) through textfields, i wish for the applet to store this information in an array when an add button below the textfeilds is pressed.
client array[];
array=new client[];//needs to be an infinate array!
I have created the client class with all the set and get methods plus constructors needed but i dont know how to take the text typed into the textfields by the user and store them in the array.
i also need to save this info to a file and be able to load it back into the applet.
Could some please help! Thank you for your time.Better maybe redefine the idea using an data structure :
public class client{
private char name[];
private char address[];
private int phone;
public class vector_clients{
private client vect[];
// methods for vect[]
What is your opinion about ???
Maybe you are looking for
-
Remote app for iPhone not connecting correctly
I use the Remote app to connect to my iTunes library. Everything worked fine until about 6 weeks ago, when the whole thing became intermittent. Sometimes it would connect, sometimes it would not. I have the remote app on my iPhone 4S running latest v
-
SNMP How to get number of learned MAC addresses on Switch interface
There is nice c2900PortNumberOfLearnedAddresses table in C2900-MIB, but it's outdated and not supported by modern switches. Is there similar table for modern switches? Most interested in Catalyst 2960 and 3750. Fetching whole forwarding table is not
-
I can't migrate to iCloud from mobile me
I asked this before, and can't find the thread, even by searching for my name, so pardon this duplicate. When I click on the iCloud icon in System Preferences, I get a prompt to move to iCloud. When I click on the button to move, I get the authentic
-
does anyone know how to delete the back up for the ipod? I am getting an error message that says "iTunes could not back up iPod because it is corrupt or not compatible with iPod; delete back up and try again"
-
Help me on my hp administra​tor password or power on power pls
Good Morning Pals, am using hp window 8 product, my junoir brother when ahaead to input power on password. he forget what he use. now my ready to print my project from it since day before yesterday. after i press the password he though he used 3 time