Java Signature toString Method with Examples



The string representation for the signature object can be obtained using the method getString() in the class java.security.Signature. This includes information such as the object state, algorithm name etc

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

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 str = signature.toString();
         System.out.println(str);
      } catch (NoSuchAlgorithmException e) {
         System.out.println("Error!!! NoSuchAlgorithmException");
      }
   }
}

Output

Signature object: SHA1withDSA
Updated on: 2019-09-23T12:42:17+05:30

141 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements