Solved

Java and Cryptix Cryptography

Posted on 2002-07-06
9
291 Views
Last Modified: 2009-07-29
In order to try to encrypt a file I have been using the Cryptix JCE toolkit, and API, but seem to have a problem in trying to get my program to compile. The code that I have is as follows (DES is just until I get it working by the way).

Cipher desCipher;
desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, key);

When I try to compile the class, I am left with the error message

cipher.java [33:1] cannot resolve symbol
symbol  : method init  (int,java.lang.String)
location: class javax.crypto.Cipher
                desCipher.init(Cipher.ENCRYPT_MODE, key);
                         ^
As far as I can tell I have all of the correct import statements in the program

import javax.crypto.*;
import javax.crypto.spec.*;
import javax.security.*;

But don't seem to be able to get it to work. (I am using SDK 1.3.0)

How can I get the program to compile (and any example code would also be useful)
0
Comment
Question by:Mikey_B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7134095
 Are you sure you are using the latest classes? If not make sure you upgrade and recompile. This error message usually means that you are trying to access a method that does not exist any more (but when the classes were written it was there).

  IF you are using the latest APIs make sure that you are trying to access the init method of the right class.

  Hope it helps.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7134099
 ... also make sure that your init method does indeed takeas parameters an int and a String.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 7134330
The key variable needs to be of type java.security.Key and not a String.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 7134410
Here's some code to generate a key pair which you couls then use and/or save to disk:

KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
kpg.initialize(1024, new SecureRandom());
KeyPair pair = kpg.generateKeyPair();
Key priv = pair.getPrivate();
Key pub = pair.getPublic();
0
 

Author Comment

by:Mikey_B
ID: 7134927
Changing the type from String, to java.security.Key stops the cannot resolve symbol message, but also means that I can't initialise it as I was trying before. How do I get the passPhrase from a String to a Key?
0
 
LVL 92

Expert Comment

by:objects
ID: 7136383
You need to create a Key object. I included code above to generate public/private keys.
0
 
LVL 92

Expert Comment

by:objects
ID: 7136792
To generate a key from a passphrase try something like this:

char[] passPhrase = "....
KeySpec spec = new PBEKeySpec(passPhrase);
SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
SecretKey key = factory.generateSecret(spec);
0
 
LVL 35

Expert Comment

by:girionis
ID: 8894085
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to objects

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Glassfish admin console not working 1 88
wild fly 8 startup error 2 78
JDBC performance 8 33
How does initial implicit objects  are set up in JSP? 7 40
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question