Java中的提供者getService()方法
使用getService()类java.security.Provider中的方法可以获得可以描述关于任何算法的Provider实现的服务。此方法需要两个参数,即所需的服务类型和所需服务的算法名称。
演示此的程序如下所示-
示例
import java.security.*;
import java.util.*;
public class Demo {
public static void main(String[] argv) throws Exception {
try {
Signature sign = Signature.getInstance("SHA256withDSA");
Provider p = sign.getProvider();
Provider.Service s = p.getService("Signature", sign.getAlgorithm());
System.out.println("The Service for the Provider is: " + s);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
}
}
}输出结果
The Service for the Provider is: SUN: Signature.SHA256withDSA -> sun.security.provider.DSA$SHA256withDSA
aliases: [OID.2.16.840.1.101.3.4.3.2, 2.16.840.1.101.3.4.3.2]
attributes: {KeySize=2048, SupportedKeyClasses=java.security.interfaces.DSAPublicKey|java.security.interfaces.DSAPrivateKey}现在让我们了解上面的程序。
该getService()方法用于获取可以描述有关任何算法的Provider实现的服务。然后显示。如果算法名称错误,则会引发异常NoSuchAlgorithmException。演示的代码片段如下-
try {
Signature sign = Signature.getInstance("SHA256withDSA");
Provider p = sign.getProvider();
Provider.Service s = p.getService("Signature", sign.getAlgorithm());
System.out.println("The Service for the Provider is: " + s);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
}热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短