
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
GetAlgorithm Method in Java
The algorithm name for the parameter generator can be obtained using the method getAlgorithm() in the class java.security.AlgorithmParameterGenerator. This method requires no parameters and it returns the algorithm name in string form.
A program that demonstrates this is given as follows −
Example
import java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) { try { AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman"); apGenerator.init(1024); String algorithm = apGenerator.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } catch (ProviderException e) { System.out.println("Error!!! ProviderException"); } } }
Output
The Algorithm is: DiffieHellman
Now let us understand the above program.
The method getAlgorithm() is used to obtain the algorithm name for the parameter generator. Then this algorithm name is displayed. If the algorithm name is wrong, then the exception NoSuchAlgorithmException is thrown. A code snippet that demonstrates is given as follows −
try { AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman"); apGenerator.init(1024); String algorithm = apGenerator.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } catch (ProviderException e) { System.out.println("Error!!! ProviderException"); }
Advertisements