java.lang.SecurityException: Prohibited package name: java.security

Hi,

I am trying to use the standard security packges in JDK :

import javax.crypto.*;

import java.security.AlgorithmParameters;

import java.security.Key;

import java.security.KeyGenerator;

andthe code :

public static void main(String[] args) {

try{

KeyGenerator keygen = KeyGenerator.getInstance("DES-EDE3");

Key myKey = keygen.generateKey();

Cipher c = Cipher.getInstance("PBEWithMD5AndDES");

c.init(Cipher.ENCRYPT_MODE, myKey);

byte[] cipherText = c.doFinal("This is just an example".getBytes());

algParams = c.getParameters();

byte[] encodedAlgParams = algParams.getEncoded();

}

catch (Exception e)

{

System.err.println("Caught exception " + e.toString());

}

}

I am getting this error :

java.lang.SecurityException: Prohibited package name: java.security

at java.lang.ClassLoader.defineClass(ClassLoader.java:524)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)

at java.net.URLClassLoader.access$100(URLClassLoader.java:55)

at java.net.URLClassLoader$1.run(URLClassLoader.java:194)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

can any body tell me how to get this code workin?

Thankyou.

[1740 byte] By [sakpaya] at [2007-11-27 3:55:19]
# 1
Does your code have a 'package' statement and if so what is it?
sabre150a at 2007-7-12 8:59:28 > top of Java-index,Security,Cryptography...
# 2
No it doesnot have any package statement.
sakpaya at 2007-7-12 8:59:28 > top of Java-index,Security,Cryptography...
# 3

> No it doesnot have any package statement.

The implication of the error message is that one of your classes has a package statement of

package java.security;

If you don't have this then there must be something funny with your compile command that makes the compiler think that you have this package somewhere. Does something in your classpath have this as a package?

sabre150a at 2007-7-12 8:59:28 > top of Java-index,Security,Cryptography...
# 4
Actually i am using Eclipse IDE for develpoment and the build path has only the standard JRE library
sakpaya at 2007-7-12 8:59:29 > top of Java-index,Security,Cryptography...
# 5
> Actually i am using Eclipse IDE for develpoment and> the build path has only the standard JRE libraryYou should not need to explicitly define the rt.jar so try building outside of eclipse without using it.
sabre150a at 2007-7-12 8:59:29 > top of Java-index,Security,Cryptography...