jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Java Encryption Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Encryption Exception" Watch "Java Encryption Exception" New topic

Java Encryption Exception

Reji Joseph

Joined: Oct 09, 2002
Posts: 1
I am using the Cryptix package for encryption and am using the RSA algorithm.
I am generating a keypair ir Public Key and Private Key as shown below.
It is generating the key pair, but when I am trying to Encrypt the message, it gives me the error:
Private Key : com.sun.net.ssl.internal.ssl.JSA_RSAPrivateKey@415de6
Public Key :com.sun.net.ssl.internal.ssl.JSA_RSAPublicKey@7bd9f2
Exception in thread "main" java.lang.NoClassDefFoundError: xjava/security/Cipher
at KeyGen.main(KeyGen.java:16)
Could u plz. help.
If in case some one could send me a sample, it would be very helpful for me.
Thanx in advance.
This is the program:
import java.security.*;
import xjava.security.*;
public class KeyGen {
public static void main(String[] args) {
try {
KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
KeyPair keypair = keygen.generateKeyPair();
PrivateKey privkey = keypair.getPrivate();
PublicKey publkey = keypair.getPublic();
System.out.println("Private Key : "+privkey);
System.out.println("Public Key :"+publkey);

Cipher cip = Cipher.getInstance("RSA");
byte[] cleartext = "Hi! This is a very secret Message.".getBytes();
System.out.println("Message : "+cleartext);
byte[] ciphertext = cip.doFinal(cleartext);
System.out.println("Encrypted : "+cleartext);
catch(Exception e) {
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
It seems the Cipher class you are trying to use is this:
So your import statement is incorrect. Replace it by import javax.crypto.*;
I agree. Here's the link: http://aspose.com/file-tools
subject: Java Encryption Exception
It's not a secret anymore!