当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Signature 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


相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Java Signature toString() method with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。