Java Signature getAlgorithm() method with Examples

Java 8Object Oriented ProgrammingProgramming

The name of the algorithm for the signature object can be obtained using the method getAlgorithm() 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 algorithm = signature.getAlgorithm();
         System.out.println("The Algorithm = " + algorithm);
      } catch (NoSuchAlgorithmException e) {
         System.out.println("Error!! NoSuchAlgorithmException");
      }
   }
}

Output

The Algorithm = SHA256withRSA

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("SHA1withDSA");
         String algorithm = signature.getAlgorithm();
         System.out.println("The Algorithm = " + algorithm);
      } catch (NoSuchAlgorithmException e) {
         System.out.println("Error!! NoSuchAlgorithmException");
      }
   }
}

Output

The Algorithm = SHA1withDSA
raja
Published on 23-Sep-2019 12:28:40
Advertisements