Now when I compile it it is ok. but when I run it it does not work why.
I did installed the patch files. is the problem is about threadlib.io.1 or
what . I could not find the solution.
By the way when I run the program I got the following error message :
yawl omar 7: java edE e omar
Exception in thread "main" java.io.InvalidClassException: com.sun.crypto.provider.DESKey; Local class not compatible: stream classdesc serialVersionUID=3507950620698800284 local class serialVersionUID=7724971015953279128
at java.lang.Throwable.<init>(Throwable.java:78)
at java.lang.Exception.<init>(Exception.java:42)
at java.io.IOException.<init>(IOException.java:47)
at java.io.ObjectStreamException.<init>(ObjectStreamException.java:29)
at java.io.InvalidClassException.<init>(InvalidClassException.java:47)
at java.io.ObjectStreamClass.validateLocalClass(ObjectStreamClass.java:434)
at java.io.ObjectStreamClass.setClass(Compiled Code @ 0xb7f3c)
at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:773)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:226)
at java.io.ObjectInputStream.inputObject(Compiled Code @ 0xaa430)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:363)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:226)
at edE.main(Compiled Code @ 0x1a7930)
yawl omar 8:
--------------------------------
The program is the following one :
import com.sun.crypto.provider.SunJCE;
import java.io.*;
import java.security.*;
import javax.crypto.*;
// import javax.crypto.spec.*;
import sun.misc.*;
// import javax.crypto.interfaces.*;
public class edE {
public static void main (String[] args) throws Exception {
// Check arguments.
SunJCE jce = new SunJCE();
Security.addProvider(jce);
//Provider sunJce = new com.sun.crypto.provider.SunJCE(); // Security.addProvider(sunJce);
if (args.length < 2) {
System.out.println("Usage: edE ");
return;
}
// get or create key.
Key key;
try {
// ObjectInputStream in = new ObjectInputStream(
// new FileInputStream("SecretKey.ser"));
ObjectInputStream in = new ObjectInputStream(
new FileInputStream("KA"));
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"));
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream("KA"));
new FileOutputStream("KA");
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[i];
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);
}
}
}
Thank you very much and I will look forward to hearing from you soon.,
omar@ee.fit.edu