本文整理了Java中java.security.Security.getProviders()
方法的一些代码示例,展示了Security.getProviders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Security.getProviders()
方法的具体详情如下:
包路径:java.security.Security
类名称:Security
方法名:getProviders
[英]Returns an array containing all installed providers. The providers are ordered according their preference order.
[中]返回包含所有已安装的提供程序的数组。提供者根据其偏好顺序进行排序。
代码示例来源:origin: square/okhttp
public static boolean isConscryptPreferred() {
// mainly to allow tests to run cleanly
if ("conscrypt".equals(Util.getSystemProperty("okhttp.platform", null))) {
return true;
}
// check if Provider manually installed
String preferredProvider = Security.getProviders()[0].getName();
return "Conscrypt".equals(preferredProvider);
}
代码示例来源:origin: apache/geode
private static boolean usesIBMProviders() {
final Provider[] providers = Security.getProviders();
for (int index = 0; index < providers.length; ++index) {
if (!providers[index].getName().toLowerCase().startsWith("ibm")) {
return false;
}
}
return true;
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
public static boolean isConscryptPreferred() {
// mainly to allow tests to run cleanly
if ("conscrypt".equals(Util.getSystemProperty("okhttp.platform", null))) {
return true;
}
// check if Provider manually installed
String preferredProvider = Security.getProviders()[0].getName();
return "Conscrypt".equals(preferredProvider);
}
代码示例来源:origin: stackoverflow.com
import java.security.Provider;
import java.security.Security;
public class SecurityListings {
public static void main(String[] args) {
for (Provider provider : Security.getProviders()) {
System.out.println("Provider: " + provider.getName());
for (Provider.Service service : provider.getServices()) {
System.out.println(" Algorithm: " + service.getAlgorithm());
}
}
}
}
代码示例来源:origin: jwtk/jjwt
public static void enableBouncyCastleIfPossible() {
if (!BOUNCY_CASTLE_AVAILABLE || bcLoaded.get()) {
return;
}
try {
Class clazz = Classes.forName(BC_PROVIDER_CLASS_NAME);
//check to see if the user has already registered the BC provider:
Provider[] providers = Security.getProviders();
for(Provider provider : providers) {
if (clazz.isInstance(provider)) {
bcLoaded.set(true);
return;
}
}
//bc provider not enabled - add it:
Security.addProvider((Provider)Classes.newInstance(clazz));
bcLoaded.set(true);
} catch (UnknownClassException e) {
//not available
}
}
代码示例来源:origin: stackoverflow.com
for (Provider p: Security.getProviders()) p.getServices().forEach(System.out::println);
代码示例来源:origin: stackoverflow.com
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
Log.i("CRYPTO","provider: "+provider.getName());
Set<Provider.Service> services = provider.getServices();
for (Provider.Service service : services) {
Log.i("CRYPTO"," algorithm: "+service.getAlgorithm());
}
}
代码示例来源:origin: wildfly/wildfly
private static <T> Iterator<T> getFactories(Class<T> type, ClassLoader classLoader, boolean includeGlobal) {
Set<T> factories = new LinkedHashSet<>();
final ServiceLoader<T> loader = ServiceLoader.load(type, classLoader);
for (T factory : loader) {
factories.add(factory);
}
if (includeGlobal) {
Set<String> loadedClasses = new HashSet<>();
final String filter = type.getSimpleName() + ".";
Provider[] providers = Security.getProviders();
for (Provider currentProvider : providers) {
final ClassLoader cl = currentProvider.getClass().getClassLoader();
currentProvider.keySet().stream().filter(currentKey -> currentKey instanceof String && ((String)currentKey).startsWith(filter)
&& ((String)currentKey).indexOf(' ') < 0).forEach(currentKey -> {
String className=currentProvider.getProperty((String)currentKey);
if(className != null && loadedClasses.add(className)) {
try {
factories.add(Class.forName(className, true, cl).asSubclass(type).newInstance());
} catch(ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException e) {
}
}
});
}
}
return factories.iterator();
}
代码示例来源:origin: Javen205/IJPay
/**
* 打jre中印算法提供者列表
*/
private static void printProviders() {
LogUtil.writeLog("Providers List:");
Provider[] providers = Security.getProviders();
for (int i = 0; i < providers.length; i++) {
LogUtil.writeLog(i + 1 + "." + providers[i].getName());
}
}
代码示例来源:origin: robovm/robovm
hm.put(filter.substring(0, i), filter.substring(i + 1));
return getProviders(hm);
代码示例来源:origin: line/armeria
/**
* Invokes the specified {@link Callable} with {@link BouncyCastleKeyFactoryProvider} enabled temporarily.
*/
public static synchronized <T> T call(Callable<T> task) throws Exception {
boolean needToAdd = true;
for (Provider provider : Security.getProviders()) {
if (provider instanceof BouncyCastleKeyFactoryProvider) {
needToAdd = false;
break;
}
}
if (needToAdd) {
Security.addProvider(new BouncyCastleKeyFactoryProvider());
try {
return task.call();
} finally {
Security.removeProvider(PROVIDER_NAME);
}
} else {
return task.call();
}
}
代码示例来源:origin: wildfly/wildfly
final String filter = type.getSimpleName() + ".";
Provider[] providers = Security.getProviders();
final SecurityManager sm = System.getSecurityManager();
for (final Provider currentProvider : providers) {
代码示例来源:origin: robovm/robovm
/**
* Returns value for the specified algorithm with the specified name.
*
* @param algName
* the name of the algorithm.
* @param propName
* the name of the property.
* @return value of the property.
* @deprecated Use {@link AlgorithmParameters} and {@link KeyFactory} instead.
*/
@Deprecated
public static String getAlgorithmProperty(String algName, String propName) {
if (algName == null || propName == null) {
return null;
}
String prop = "Alg." + propName + "." + algName;
Provider[] providers = getProviders();
for (Provider provider : providers) {
for (Enumeration e = provider.propertyNames(); e.hasMoreElements(); ) {
String propertyName = (String) e.nextElement();
if (propertyName.equalsIgnoreCase(prop)) {
return provider.getProperty(propertyName);
}
}
}
return null;
}
代码示例来源:origin: robovm/robovm
private static synchronized void checkCacheVersion() {
int newCacheVersion = Services.getCacheVersion();
if (newCacheVersion != cacheVersion) {
//
// Now search providers for mappings like
// Alg.Alias.<service>.<OID-INTS-DOT-SEPARATED>=<alg-name>
// or
// Alg.Alias.<service>.OID.<OID-INTS-DOT-SEPARATED>=<alg-name>
//
Provider[] pl = Security.getProviders();
for (Provider element : pl) {
selectEntries(element);
}
cacheVersion = newCacheVersion;
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a {@code Set} of all registered algorithms for the specified
* cryptographic service. {@code "Signature"}, {@code "Cipher"} and {@code
* "KeyStore"} are examples for such kind of services.
*
* @param serviceName
* the case-insensitive name of the service.
* @return a {@code Set} of all registered algorithms for the specified
* cryptographic service, or an empty {@code Set} if {@code
* serviceName} is {@code null} or if no registered provider
* provides the requested service.
*/
public static Set<String> getAlgorithms(String serviceName) {
Set<String> result = new HashSet<String>();
// compatibility with RI
if (serviceName == null) {
return result;
}
for (Provider provider : getProviders()) {
for (Provider.Service service: provider.getServices()) {
if (service.getType().equalsIgnoreCase(serviceName)) {
result.add(service.getAlgorithm());
}
}
}
return result;
}
代码示例来源:origin: wildfly/wildfly
private KeyStore getKeyStoreInstance(String type) throws CredentialStoreException {
if (providers != null) {
for (Provider p: providers) {
try {
return KeyStore.getInstance(type, p);
} catch (KeyStoreException e) {
// no such keystore type in provider, ignore
}
}
}
try {
if (log.isTraceEnabled()) {
log.tracef("Obtaining KeyStore instance of type %s, providers: %s", type, Arrays.toString(Security.getProviders()));
}
KeyStore ks = KeyStore.getInstance(type);
log.tracef("Obtained KeyStore instance: %s", ks);
return ks;
} catch (KeyStoreException e) {
throw log.cannotInitializeCredentialStore(e);
}
}
代码示例来源:origin: voldemort/voldemort
private void testBouncyCastleProvider() throws IOException {
Properties properties = new Properties();
// Use bouncy castle as first choice of JCE provider.
properties.setProperty("use.bouncycastle.for.ssl", "true");
server = getVoldemortServer(properties);
assertEquals(BouncyCastleProvider.PROVIDER_NAME, Security.getProviders()[0].getName());
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldPreferBouncyCastleProvider() throws Exception {
assertThat(Security.getProviders()[0], is(equalTo(bcProvider)));
}
代码示例来源:origin: syncany/syncany
@Test
public void listCryptoSettingsAvailable() {
logger.log(Level.INFO, "Listing security providers and properties:");
for (Provider provider: Security.getProviders()) {
logger.log(Level.INFO, "- Provider '"+provider.getName()+"' ");
List<String> propertyNames = new ArrayList<String>();
propertyNames.addAll(provider.stringPropertyNames());
Collections.sort(propertyNames);
for (String key : propertyNames) {
logger.log(Level.INFO, " "+provider.getName()+" / "+key+" = "+provider.getProperty(key));
}
}
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
{ "\n", null, null, BigDecimal.class },
{ Security.getProviders()[0].getName(), Security.getProviders()[0], null, Provider.class },
{ "\n", null, null, Provider.class },
内容来源于网络,如有侵权,请联系作者删除!