What is the Signature getInstance() method in Java?

Overview

Applications can access the capabilities of a digital signature algorithm using the Signature class. To authenticate and guarantee the integrity of digital data, digital signatures are utilized.

The getInstance() method is a static method of the Signature class that returns an instance of the Signature class that implements the specified signature algorithm. The signature algorithm can be specified as a string or as an implementation of the Provider class. The method throws NoSuchAlgorithmException if the specified algorithm or provider is not available.

Syntax

public static Signature getInstance(String algorithm)

Parameter

  • algorithm: This is the name of the signature algorithm.

Return value

The method returns a Signature object.

Code

import java.security.*;
public class Main{
public static void main(String[] args) {
try {
String algorithm = "SHA224withRSA";
Signature signature = Signature.getInstance(algorithm);
System.out.println("Signature object : " + signature.toString());
} catch (NoSuchAlgorithmException e) {
System.out.println("Exception : " + e);
}
}
}

Explanation

  • Line 7: We define the signature algorithm.
  • Line 8: We obtain an instance of the Signature class using the getInstance() method by specifying the algorithm defined in Line 7.
  • Line 9: We print the signature object.
  • Lines 10–11: We catch the NoSuchAlgorithmException exception and print it.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved