Java Signature toString()方法及其示例

这个 toString() 方法 JAVA安全签名 类用于返回签名对象的字符串表示形式,提供包括对象状态和所用算法名称的信息。

null

语法:

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

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享