use of java.security.Provider in project poi by apache.
the class CryptoFunctions method registerBouncyCastle.
@SuppressWarnings("unchecked")
public static void registerBouncyCastle() {
if (Security.getProvider("BC") != null) {
return;
}
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
String bcProviderName = "org.bouncycastle.jce.provider.BouncyCastleProvider";
Class<Provider> clazz = (Class<Provider>) cl.loadClass(bcProviderName);
Security.addProvider(clazz.newInstance());
} catch (Exception e) {
throw new EncryptedDocumentException("Only the BouncyCastle provider supports your encryption settings - please add it to the classpath.", e);
}
}
use of java.security.Provider in project robovm by robovm.
the class TrustManagerFactoryTest method test_TrustManagerFactory_getInstance.
public void test_TrustManagerFactory_getInstance() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
Set<Provider.Service> services = provider.getServices();
for (Provider.Service service : services) {
String type = service.getType();
if (!type.equals("TrustManagerFactory")) {
continue;
}
String algorithm = service.getAlgorithm();
{
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
assertEquals(algorithm, tmf.getAlgorithm());
test_TrustManagerFactory(tmf);
}
{
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm, provider);
assertEquals(algorithm, tmf.getAlgorithm());
assertEquals(provider, tmf.getProvider());
test_TrustManagerFactory(tmf);
}
{
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm, provider.getName());
assertEquals(algorithm, tmf.getAlgorithm());
assertEquals(provider, tmf.getProvider());
test_TrustManagerFactory(tmf);
}
}
}
}
use of java.security.Provider in project robovm by robovm.
the class Security2Test method getProvidersCount.
private int getProvidersCount(Map filterMap) {
int result = 0;
Provider[] allProviders = Security.getProviders();
// for each provider
for (Provider provider : allProviders) {
Set allProviderKeys = provider.keySet();
boolean noMatchFoundForFilterEntry = false;
// for each filter item
for (Object filter : filterMap.keySet()) {
String filterString = (String) filter;
// but I have seen them)
if (filterString.endsWith("=")) {
filterString = filterString.substring(0, filterString.length() - 1);
}
if (filterString != null) {
if (filterString.indexOf(" ") == -1) {
// current provider ?
if (!allProviderKeys.contains(filterString)) {
// alias.
if (!allProviderKeys.contains("Alg.Alias." + filterString)) {
noMatchFoundForFilterEntry = true;
// out of while loop
break;
}
}
} else {
// handle filter strings with attribute names
if (allProviderKeys.contains(filterString)) {
// Does the corresponding values match ?
String filterVal = (String) filterMap.get(filterString);
String providerVal = (String) provider.get(filterString);
if (providerVal == null || !providerVal.equals(filterVal)) {
noMatchFoundForFilterEntry = true;
// out of while loop
break;
}
}
// end if filter string with named attribute is
// found
}
// end else
}
// end if non-null key
}
if (!noMatchFoundForFilterEntry) {
// Current provider is a match for the filterMap
result++;
}
}
return result;
}
use of java.security.Provider in project robovm by robovm.
the class SecurityTest method testGetAlgorithmPropertyLjava_lang_String_java_lang_String.
/**
* java.security.Security#getAlgorithmProperty(String algName, String
* propName)
* @disabled because Security.getAlgorithmProperty looks for
* "propName.algName" instead of "Alg.propName.algName"
*/
@SuppressWarnings("deprecation")
public final void testGetAlgorithmPropertyLjava_lang_String_java_lang_String() {
Provider provider = new MyProvider();
Map<String, String> m = new HashMap<String, String>();
m.clear();
m.put("Alg.propName.algName", "value");
provider.putAll(m);
try {
Security.addProvider(provider);
assertNotNull(Security.getAlgorithmProperty("algName", "propName"));
assertNull(Security.getAlgorithmProperty("DSA", null));
assertNull(Security.getAlgorithmProperty("DSA", "propName"));
} finally {
Security.removeProvider(provider.getName());
}
}
use of java.security.Provider in project robovm by robovm.
the class SecurityTest method testGetProviders.
/**
* Test that Security.getProviders does case sensitive operations
* independent of its locale.
*/
private void testGetProviders(Locale locale) {
Locale defaultLocale = Locale.getDefault();
Locale.setDefault(locale);
Provider p = new MyProvider();
try {
Security.addProvider(p);
String filter = "MyService.MyAlgorithm";
assertTrue(filter, Arrays.equals(new Provider[] { p }, Security.getProviders(filter)));
filter = "MyService.MyAlgorithm KeySize:512";
assertTrue(filter, Arrays.equals(new Provider[] { p }, Security.getProviders(filter)));
filter = "MyService.MyAlgorithm KeySize:1025";
assertNull(filter, Security.getProviders(filter));
// attribute name and value are case insensitive
filter = "MyService.MyAlgorithm imPLementedIn:softWARE";
assertTrue(filter, Arrays.equals(new Provider[] { p }, Security.getProviders(filter)));
filter = "MyService.MyAlgorithm ATTribute:attributeVALUE";
assertTrue(filter, Arrays.equals(new Provider[] { p }, Security.getProviders(filter)));
// Turkish dotless i
filter = "MyService.MyAlgorithm İmPLementedın:softWARE";
assertTrue(filter, Arrays.equals(new Provider[] { p }, Security.getProviders(filter)));
// Regression for HARMONY-2761
filter = "MyService.NoKeySize KeySize:512";
assertNull(filter, Security.getProviders(filter));
filter = "MyService.NoImplementedIn ImplementedIn:Software";
assertNull(filter, Security.getProviders(filter));
filter = "ABCService.NoAttribute Attribute:ABC";
assertNull(filter, Security.getProviders(filter));
} finally {
// clean up
Security.removeProvider(p.getName());
Locale.setDefault(defaultLocale);
}
}
Aggregations