Java如何获取加密安全提供程序
package org.nhooo.example.security; import java.security.Provider; import java.security.Security; import java.util.Set; import java.util.HashSet; public class SecurityProvider { public static void main(String[] args) { //创建一个集合,以便我们获得独特的结果。 Set result = new HashSet(); //返回包含所有已安装的提供程序的数组。 Provider[] providers = Security.getProviders(); for (Provider provider : providers) { //获取提供者的属性密钥 Set keys = provider.keySet(); for (Object key : keys) { String data = (String) key; data = data.split(" ")[0]; //服务类型以“Alg.Alias”字符串开头"Alg.Alias" string if (data.startsWith("Alg.Alias")) { data = data.substring(10); } data = data.substring(0, data.indexOf('.')); result.add(data); } } for (Object o : result) { System.out.println("Service Type = " + o); } } }
我们的代码的示例结果:
Service Type = KeyFactoryService Type = TransformServiceService Type = CertPathBuilderService Type = CipherService Type = SecureRandomService Type = SignatureService Type = AlgorithmParameterGeneratorService Type = KeyPairGeneratorService Type = XMLSignatureFactoryService Type = CertificateFactoryService Type = MessageDigestService Type = KeyInfoFactoryService Type = KeyAgreementService Type = CertStoreService Type = ConfigurationService Type = SSLContextService Type = SaslServerFactoryService Type = AlgorithmParametersService Type = TrustManagerFactoryService Type = GssApiMechanismService Type = TerminalFactoryService Type = MacService Type = KeyGeneratorService Type = PolicyService Type = CertPathValidatorService Type = SaslClientFactoryService Type = SecretKeyFactoryService Type = KeyManagerFactoryService Type = KeyStoreService Type = Provider