- 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
Java Signature getAlgorithm() method
The name of the algorithm for the signature object can be obtained using the method getAlgorithm() in the class java.security.Signature. This method requires no parameters and it returns the name of the algorithm for the signature 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 { Signature signature = Signature.getInstance("SHA256withRSA"); String algorithm = signature.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }
Output
The Algorithm is: SHA256withRSA
Now let us understand the above program.
The method getAlgorithm() is used to obtain the name of the algorithm for the signature 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 { Signature signature = Signature.getInstance("SHA256withRSA"); String algorithm = signature.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); }
- Related Articles
- Java Signature getAlgorithm() method with Examples
- SecureRandom getAlgorithm() method in Java
- KeyPairGenerator getAlgorithm() method in Java
- KeyFactory getAlgorithm() method in Java
- AlgorithmParameterGenerator getAlgorithm() method in Java
- Java Signature getProvider() method
- Java Signature toString() method
- Java Signature getInstance() method
- Java Signature getInstance() method with Examples
- Java Signature getProvider() method with Examples
- Java Signature initSign() method with Examples
- Java Signature toString() method with Examples
- What is a method signature in Java?
- Can we change method signature in overriding in Java?
- Difference Between Digital Signature and Electronic Signature

Advertisements