Results 1 to 17 of 17
Thread: KeyPair
- 09-08-2010, 10:09 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
KeyPair
hi,
My library doesn't support "KeyPair".
my code is:
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),
RSAPublicKeySpec.class);
BigInteger x = pub.getModulus();
The error is: Type mismatch: cannot convert from cryptobag to keypair
How can I get the library?
- 09-08-2010, 11:47 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
What library?
And have you read its API to find out how to use it?
- 09-08-2010, 11:59 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
I think my library isn't complete.
Java.security
- 09-08-2010, 12:08 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
OK.
Can you give us the full compilation error you're getting (as it appears), and show us the line it occurs on, as well as the import statements, and the code around the line that's failing.
ETA: What version of the JDK are you using?
ETA2: And use CODE tags when posting code.
- 09-08-2010, 12:43 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
This error is before compilation. I can't compile it.
yesterday I got jdk-6u21 and install it.
//Creating an RSA key pair in Java
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
//get RSA module
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),
RSAPublicKeySpec.class);
BigInteger x = pub.getModulus();
- 09-08-2010, 12:48 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Wh at do you mean you can't compile it?
javac doesn't work?
- 09-08-2010, 12:56 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
When I wrote "KeyPair kp = kpg.genKeyPair();", I got error this error: "Type mismatch: cannot convert from cryptobag to keypair"
If I change it to cryptobag which library is iaik,I will have some problems too.
- 09-08-2010, 12:58 PM #8
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
When I wrote "KeyPair kp = kpg.genKeyPair();", I got this error: "Type mismatch: cannot convert from cryptobag to keypair"
If I change it to cryptobag which library is iaik,I will have some problems too.
- 09-08-2010, 01:36 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Since cryptobag is not part of the Sun security package then I can only presume you are importing something that is clashing with KeyPairGenerator.
I take it you are using some IDE then? Also, make sure you post errors correctly, because keypair is not the class...KeyPair is.
- 09-08-2010, 03:42 PM #10
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
I'm using Eclipse.
Yes, You're right. that's KeyPair.
I think my library doesn't know KeyPair,that's why it give me error..What should I do?
- 09-08-2010, 03:48 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
What do your imports look like?
(I did ask earlier)
- 09-08-2010, 03:51 PM #12
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
import java.math.BigInteger;
import java.security.Key;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.spec.DSAPrivateKeySpec;
import java.security.spec.DSAPublicKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPrivateKeySpec;
import iaik.me.security.Cipher;
import iaik.me.security.CryptoBag;
import iaik.me.security.CryptoException;
import iaik.me.security.KeyPairGenerator;
import iaik.me.security.PrivateKey;
import iaik.me.security.PublicKey;
import iaik.me.security.SecureRandom;
import iaik.me.security.Signature;
import iaik.me.security.rsa.RSAKeyPairGenerator;
- 09-08-2010, 03:58 PM #13
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
What happens if you just delete all the spurious lines starting with "import iaik.me.security"..."?
Neil Coffey
Javamex - Java tutorials and performance info
- 09-08-2010, 04:05 PM #14
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
you're excellent.Thx a lot.
- 09-08-2010, 04:29 PM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
import iaik.me.security.KeyPairGenerator;
So you weren't using java.security.KeyPairGenerator...hence your problem.
- 09-08-2010, 06:33 PM #16
Member
- Join Date
- Sep 2010
- Posts
- 37
- Rep Power
- 0
Yes!! You're great.:)
- 09-09-2010, 08:34 AM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks