Results 1 to 17 of 17

Thread: KeyPair

  1. #1
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Unhappy 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?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    What library?
    And have you read its API to find out how to use it?

  3. #3
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Question

    I think my library isn't complete.
    Java.security

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    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.

  5. #5
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Default

    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();

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Wh at do you mean you can't compile it?
    javac doesn't work?

  7. #7
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Default

    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.

  8. #8
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Default

    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.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    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.

  10. #10
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Default

    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?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    What do your imports look like?
    (I did ask earlier)

  12. #12
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Default

    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;

  13. #13
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    What happens if you just delete all the spurious lines starting with "import iaik.me.security"..."?

  14. #14
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Default

    you're excellent.Thx a lot.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    import iaik.me.security.KeyPairGenerator;

    So you weren't using java.security.KeyPairGenerator...hence your problem.

  16. #16
    bobo67 is offline Member
    Join Date
    Sep 2010
    Posts
    37
    Rep Power
    0

    Wink

    Yes!! You're great.:)

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •