Results 1 to 8 of 8
Thread: NoSuchAlgorithmException
- 04-26-2010, 03:56 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
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?
-
- 04-26-2010, 04:08 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
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:
and this tells me that there's nothing wrong with your jre or jdk.throws NoSuchAlgorithmException
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 04:16 AM.
- 04-26-2010, 04:17 AM #5
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
- 04-26-2010, 04:24 AM #6
Member
- Join Date
- Apr 2010
- Posts
- 19
- Rep Power
- 0
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 04:34 AM. Reason: I LEARNED SOMETHING! TODAY SHOULD BE A WORLDWIDE HOLIDAY!
-
- 04-26-2010, 04:35 AM #8
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
From KeyPairGenerator (Java Platform SE 6)
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.Java Code:public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
-Gary-


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks