use of java.security.Provider.Service in project Bytecoder by mirkosertic.
the class GetInstance method getInstance.
public static Instance getInstance(String type, Class<?> clazz, String algorithm, Object param) throws NoSuchAlgorithmException {
List<Service> services = getServices(type, algorithm);
NoSuchAlgorithmException failure = null;
for (Service s : services) {
try {
return getInstance(s, clazz, param);
} catch (NoSuchAlgorithmException e) {
failure = e;
}
}
if (failure != null) {
throw failure;
} else {
throw new NoSuchAlgorithmException(algorithm + " " + type + " not available");
}
}
use of java.security.Provider.Service in project certmgr by hdecarne.
the class KeyPairAlgorithm method getDefaultSet.
/**
* Get the available key pair algorithms.
*
* @param defaultHint The default to return (may be {@code null}). If this algorithm is contained in the default
* set, it is also set as the default.
* @param expertMode Whether only standard algorithms are considered ({@code false}) or all algorithms available on
* the current platform ({@code true}).
* @return The available key pair algorithms
*/
public static DefaultSet<KeyPairAlgorithm> getDefaultSet(@Nullable String defaultHint, boolean expertMode) {
DefaultSet<KeyPairAlgorithm> keyPairAlgorithms = new DefaultSet<>();
DefaultSet<String> defaultNames = SecurityDefaults.getKeyAlgorithmNames();
@Nullable String defaultName = (defaultHint != null && defaultNames.contains(defaultHint) ? defaultHint : defaultNames.getDefault());
for (Provider provider : SecurityDefaults.getProviders(expertMode)) {
for (Provider.Service service : provider.getServices()) {
if (!SERVICE_TYPE_KEY_PAIR_GENERATOR.equals(service.getType())) {
continue;
}
String algorithm = service.getAlgorithm();
if (!expertMode && !defaultNames.contains(algorithm)) {
continue;
}
KeyPairAlgorithm keyPairAlgorithm = (expertMode ? new ExpertKeyPairAlgorithm(service) : new StandardKeyPairAlgorithm(service));
if (algorithm.equals(defaultName)) {
keyPairAlgorithms.addDefault(keyPairAlgorithm);
} else {
keyPairAlgorithms.add(keyPairAlgorithm);
}
}
}
return keyPairAlgorithms;
}
use of java.security.Provider.Service in project certmgr by hdecarne.
the class PlatformKeyStore method getDefaultSet.
/**
* Get the available platform key stores.
*
* @return The available platform key stores.
*/
public static DefaultSet<PlatformKeyStore> getDefaultSet() {
DefaultSet<PlatformKeyStore> platformKeyStores = new DefaultSet<>();
DefaultSet<String> defaultNames = SecurityDefaults.getPlatformKeyStoreNames();
String defaultName = defaultNames.getDefault();
for (Provider provider : Security.getProviders()) {
for (Provider.Service service : provider.getServices()) {
if (!SERVICE_TYPE_KEY_STORE.equals(service.getType())) {
continue;
}
String algorithm = service.getAlgorithm();
if (!defaultNames.contains(algorithm)) {
continue;
}
PlatformKeyStore platformKeyStore = new PlatformKeyStore(service);
if (algorithm.equals(defaultName)) {
platformKeyStores.addDefault(platformKeyStore);
} else {
platformKeyStores.add(platformKeyStore);
}
}
}
return platformKeyStores;
}
use of java.security.Provider.Service in project android-pbe by nelenkov.
the class Crypto method listAlgorithms.
public static void listAlgorithms(String algFilter) {
Provider[] providers = Security.getProviders();
for (Provider p : providers) {
String providerStr = String.format("%s/%s/%f\n", p.getName(), p.getInfo(), p.getVersion());
Log.d(TAG, providerStr);
Set<Service> services = p.getServices();
List<String> algs = new ArrayList<String>();
for (Service s : services) {
boolean match = true;
if (algFilter != null) {
match = s.getAlgorithm().toLowerCase().contains(algFilter.toLowerCase());
}
if (match) {
String algStr = String.format("\t%s/%s/%s", s.getType(), s.getAlgorithm(), s.getClassName());
algs.add(algStr);
}
}
Collections.sort(algs);
for (String alg : algs) {
Log.d(TAG, "\t" + alg);
}
Log.d(TAG, "");
}
}
use of java.security.Provider.Service in project j2objc by google.
the class KeyFactory method nextSpi.
/**
* Update the active KeyFactorySpi of this class and return the next
* implementation for failover. If no more implemenations are
* available, this method returns null. However, the active spi of
* this class is never set to null.
*/
private KeyFactorySpi nextSpi(KeyFactorySpi oldSpi) {
synchronized (lock) {
// try that spi now
if ((oldSpi != null) && (oldSpi != spi)) {
return spi;
}
if (serviceIterator == null) {
return null;
}
while (serviceIterator.hasNext()) {
Service s = serviceIterator.next();
try {
Object obj = s.newInstance(null);
if (obj instanceof KeyFactorySpi == false) {
continue;
}
KeyFactorySpi spi = (KeyFactorySpi) obj;
provider = s.getProvider();
this.spi = spi;
return spi;
} catch (NoSuchAlgorithmException e) {
// ignore
}
}
serviceIterator = null;
return null;
}
}
Aggregations