可以使用getAlgorithm()
类java.security.Signature中的方法获得签名对象的算法名称。
现在让我们看一个例子-
import java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { try { Signature signature = Signature.getInstance("SHA256withRSA"); String algorithm = signature.getAlgorithm(); System.out.println("The Algorithm = " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!! NoSuchAlgorithmException"); } } }
输出结果
The Algorithm = SHA256withRSA
现在让我们来看另一个示例-
import java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { try { Signature signature = Signature.getInstance("SHA1withDSA"); String algorithm = signature.getAlgorithm(); System.out.println("The Algorithm = " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!! NoSuchAlgorithmException"); } } }
输出结果
The Algorithm = SHA1withDSA