- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
SecureRandom getAlgorithm() method in Java
The name of the algorithm for the SecureRandom object can be obtained using the method getAlgorithm() in the class java.security.SecureRandom. This method requires no parameters and it returns the name of the algorithm for the SecureRandom object.
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 { SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG"); String algorithmName = sRandom.getAlgorithm(); System.out.println("The Algorithm is: " + algorithmName); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }
Output
The Algorithm is: SHA1PRNG
Now let us understand the above program.
The method getAlgorithm() is used to obtain the name of the algorithm for the SecureRandom object. 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 { SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG"); String algorithmName = sRandom.getAlgorithm(); System.out.println("The Algorithm is: " + algorithmName); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); }
- Related Articles
- KeyPairGenerator getAlgorithm() method in Java
- KeyFactory getAlgorithm() method in Java
- AlgorithmParameterGenerator getAlgorithm() method in Java
- SecureRandom getInstance() method in Java
- SecureRandom generateSeed() method in Java
- SecureRandom getProvider() method in Java
- SecureRandom setSeed() method in Java
- SecureRandom getSeed() method in Java
- SecureRandom nextBytes() method in Java
- Java Signature getAlgorithm() method
- Java Signature getAlgorithm() method with Examples
- Collections.replaceAll() method and List.replaceAll() method in Java
- Method overloading in Java
- Method overriding in Java
- BigInteger.isProbablePrime() method in Java

Advertisements