Mikey_B
asked on
Java and Cryptix Cryptography
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/EC B/PKCS5Pad ding");
desCipher.init(Cipher.ENCR YPT_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.ENCR YPT_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)
Cipher desCipher;
desCipher = Cipher.getInstance("DES/EC
desCipher.init(Cipher.ENCR
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.ENCR
^
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)
... also make sure that your init method does indeed takeas parameters an int and a String.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's some code to generate a key pair which you couls then use and/or save to disk:
KeyPairGenerator kpg = KeyPairGenerator.getInstan ce(algorit hm);
kpg.initialize(1024, new SecureRandom());
KeyPair pair = kpg.generateKeyPair();
Key priv = pair.getPrivate();
Key pub = pair.getPublic();
KeyPairGenerator kpg = KeyPairGenerator.getInstan
kpg.initialize(1024, new SecureRandom());
KeyPair pair = kpg.generateKeyPair();
Key priv = pair.getPrivate();
Key pub = pair.getPublic();
ASKER
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?
You need to create a Key object. I included code above to generate public/private keys.
To generate a key from a passphrase try something like this:
char[] passPhrase = "....
KeySpec spec = new PBEKeySpec(passPhrase);
SecretKeyFactory factory = SecretKeyFactory.getInstan ce(algorit hm);
SecretKey key = factory.generateSecret(spe c);
char[] passPhrase = "....
KeySpec spec = new PBEKeySpec(passPhrase);
SecretKeyFactory factory = SecretKeyFactory.getInstan
SecretKey key = factory.generateSecret(spe
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
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
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.