📜  带有示例的Java签名 toString() 方法

📅  最后修改于: 2022-05-13 01:54:34.653000             🧑  作者: Mango

带有示例的Java签名 toString() 方法

Java.security.Signature类的toString()方法用于返回签名对象的字符串表示,提供包括对象状态和所用算法名称的信息。

句法:

public String toString()

返回值:此方法返回此签名对象的字符串表示形式

下面是说明toString()方法的示例:

示例 1:

// Java program to demonstrate
// toString() method
  
import java.security.*;
import java.util.*;
  
public class GFG1 {
    public static void main(String[] argv)
    {
        try {
  
            // creating the object of Signature
            Signature sr = Signature.getInstance("SHA1withDSA");
  
            // getting the String representation
            // by using method toString()
            String status = sr.toString();
  
            // printing the provider name
            System.out.println("Status : " + status);
        }
  
        catch (NoSuchAlgorithmException e) {
  
            System.out.println("Exception thrown : " + e);
        }
    }
}
输出:
Status : Signature object: SHA1withDSA

示例 2:

// Java program to demonstrate
// toString() method
  
import java.security.*;
import java.util.*;
  
public class GFG1 {
    public static void main(String[] argv)
    {
        try {
  
            // creating the object of Signature
            Signature sr = Signature.getInstance("NONEwithDSA");
  
            // getting the String representation
            // by using method toString()
            String status = sr.toString();
  
            // printing the provider name
            System.out.println("Status : " + status);
        }
  
        catch (NoSuchAlgorithmException e) {
  
            System.out.println("Exception thrown : " + e);
        }
    }
}
输出:
Status : Signature object: NONEwithDSA