Java Signature getInstance() method with Examples

Java 8Object Oriented ProgrammingProgramming

A signature object that can implement the required signature algorithm can be obtained using the method getInstance() in the class java.security.Signature.

Let us now see an example −

Example

import java.security.*;
import java.util.*;
public class Main {
   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>

Let us now see another example −

Example

import java.security.*;
import java.util.*;
public class Main {
   public static void main(String[] argv) {
      try {
         Signature signature = Signature.getInstance("SHA1WithRSA");
         String str = signature.toString();
         System.out.println(str);
      } catch (NoSuchAlgorithmException e) {
         System.out.println("Error!!! NoSuchAlgorithmException");
      }
   }
}

Output

Signature object: SHA1WithRSA<not initialized>
raja
Published on 23-Sep-2019 12:30:32
Advertisements