On Hold Solutions

Omar Ba_rukab (omar@yacht.ee.fit.edu)
Sun, 15 Nov 1998 13:34:36 -0500

Dear Sir;
I did compile this file with java 1.2 beta 3 and it works fine. But when I down
loaded the java 1.2 beta 4 it does give me the following message :
yawl omar 10: javac edE.java
edE.java:2: Class com.sun.crypto.provider.SunJCE not found in import.
import com.sun.crypto.provider.SunJCE;
^
edE.java:5: Package javax.crypto not found in import.
import javax.crypto.*;
^
2 errors

with java 1.2 beta 3 the two comment lines denoted by 1 and 2 works fine . But when I tried to comment them and use the netxt two lines to them with java beta4
it gives me the above message. what is the problem.
the program is :
// edE.java
import com.sun.crypto.provider.SunJCE;
import java.io.*;
import java.security.*;
import javax.crypto.*;
import sun.misc.*;
public class edE {
public static void main (String[] args) throws Exception {
// Check arguments.
// 1 SunJCE jce = new SunJCE();
//2 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);
}
}