- 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 getInstance() method
A signature object that can implement the required signature algorithm can be obtained using the method getInstance() in the class java.security.Signature. This method requires a single parameter i.e. the standard algorithm name and it returns 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 str = signature.toString(); System.out.println(str); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }
Output
Signature object: SHA256withRSA<not initialized>
Now let us understand the above program.
The method getInstance() is used to obtain the signature object that can implement the required signature algorithm. Then the string representation for the signature object 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 str = signature.toString(); System.out.println(str); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); }
Advertisements
To Continue Learning Please Login
Login with Google