Results 1 to 8 of 8
  1. #1
    soccermiles is offline Member
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Question NoSuchAlgorithmException

    I am trying to make an asymetrical encryption using RSA algorithms in java.
    Every time I use the following kind of reference...

    KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");

    ...The IDE underlines it in red and says...

    "unreported exception java.security.NoSuchAlgorithmException;must be caught or declared to be thrown"

    ...My questions are...
    1) Why am I getting a "NoSuchAlgorithm" exception?
    2) What is "catching"? What about "Declaring"? Throwing?
    3) if I "caught", "declared" or "threw" this exception, would the program still work as planned?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by soccermiles View Post
    1) Why am I getting a "NoSuchAlgorithm" exception?
    2) What is "catching"? What about "Declaring"? Throwing?
    Check out the tutorials on "Exceptions"

    3) if I "caught", "declared" or "threw" this exception, would the program still work as planned?
    Try it, you've got nothing to lose. :)

  3. #3
    soccermiles is offline Member
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default

    A lot of other people have programs that work that include that exact same line, along with alot of others using "getInstance("RSA")", I think it's my jre or jdk.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by soccermiles View Post
    A lot of other people have programs that work that include that exact same line, along with alot of others using "getInstance("RSA")", I think it's my jre or jdk.
    You might not want to be so quick to blame something you're not familiar with. Have you looked at the KeyPairGenerator API, in particular the getInstance(String algorithm) method? To be honest, I know nothing about using this class to encrypt (or encryption in general), but the API tells me all I need to know, stating:

    throws NoSuchAlgorithmException
    and this tells me that there's nothing wrong with your jre or jdk.

    Again, please have a look at the Exceptions section of the tutorials. It's a very helpful article.

    Much luck.
    Last edited by Fubarable; 04-26-2010 at 05:16 AM.

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by soccermiles View Post
    A lot of other people have programs that work that include that exact same line, along with alot of others using "getInstance("RSA")", I think it's my jre or jdk.
    It's not. But you do need to learn about Exceptions, and how to catch and throw them, as Fubarable said. You'll need to learn this sooner or later anyway, and now's as good a time as any.

    -Gary-

  6. #6
    soccermiles is offline Member
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default

    Plenty of other people use this line, without using ANY exception handling code.
    I think mebbe I should check the class itself, and find out whether it actually has the Algorithm in it. mebbe its called something else...

    NVMNVMNVM!!
    I LOOKED AND NOW I KNOW A LITTLE BIT ABOUT EXCEPTION HANDLING AND IT WORKED OMGOMGOMGOMGOMGOMGOMG xD
    TYTYTYTYTYTYTY.
    Last edited by soccermiles; 04-26-2010 at 05:34 AM. Reason: I LEARNED SOMETHING! TODAY SHOULD BE A WORLDWIDE HOLIDAY!

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by soccermiles View Post
    Plenty of other people use this line, without using ANY exception handling code.
    Can you show us a link demonstrating this?

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by soccermiles View Post
    Plenty of other people use this line, without using ANY exception handling code.
    I think mebbe I should check the class itself, and find out whether it actually has the Algorithm in it. mebbe its called something else...
    From KeyPairGenerator (Java Platform SE 6)
    Java Code:
    public static KeyPairGenerator getInstance(String algorithm)
                                        throws NoSuchAlgorithmException
    The method you are trying to call clearly throws a NoSuchAlgorithmException, so you either need to catch it, or declare that your method throws it too.

    -Gary-

Tags for this Thread

Posting Permissions

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