Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java Encryption Exception  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
Public Key
Exception in thread "main" java.lang.NoClassDefFoundError: xjava/security/Cipher
at KeyGen.main(
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:
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) {
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the Cipher class you are trying to use is this:
So your import statement is incorrect. Replace it by import javax.crypto.*;
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!