use of java.security.Provider in project robovm by robovm.
the class Services method removeProvider.
/**
* Removes the provider at the specified 1-based position.
*/
public static synchronized void removeProvider(int providerNumber) {
Provider p = providers.remove(providerNumber - 1);
providersNames.remove(p.getName());
setNeedRefresh();
}
use of java.security.Provider in project robovm by robovm.
the class AlgorithmParameterGenerator2Test method testGetInstance03.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code>
* method
* Assertions:
* throws NullPointerException must be thrown is null
* throws NoSuchAlgorithmException must be thrown if algorithm is not available
* throws IllegalArgumentException when provider is null;
* returns AlgorithmParameterGenerator object
*/
public void testGetInstance03() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException {
try {
AlgorithmParameterGenerator.getInstance(null, mProv);
fail("NullPointerException or NoSuchAlgorithmException should be thrown");
} catch (NullPointerException e) {
} catch (NoSuchAlgorithmException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
AlgorithmParameterGenerator.getInstance(invalidValues[i], mProv);
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
Provider prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
AlgorithmParameterGenerator.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
AlgorithmParameterGenerator apG;
for (int i = 0; i < validValues.length; i++) {
apG = AlgorithmParameterGenerator.getInstance(validValues[i], mProv);
assertEquals("Incorrect algorithm", apG.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", apG.getProvider(), mProv);
checkResult(apG);
}
}
use of java.security.Provider in project robovm by robovm.
the class CertificateTest method testVerifyMD5.
public void testVerifyMD5() throws Exception {
Provider[] providers = Security.getProviders("CertificateFactory.X509");
for (Provider provider : providers) {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", provider);
Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCertMD5.getBytes()));
certificate.verify(certificate.getPublicKey());
}
}
use of java.security.Provider in project robovm by robovm.
the class MacTest method test_getInstance_OpenSSL_ENGINE.
public void test_getInstance_OpenSSL_ENGINE() throws Exception {
final String secret = "-HMAC-test1";
final byte[] testString = "testing123".getBytes();
Provider p = Security.getProvider(OpenSSLProvider.PROVIDER_NAME);
NativeCryptoTest.loadTestEngine();
OpenSSLEngine engine = OpenSSLEngine.getInstance(NativeCryptoTest.TEST_ENGINE_ID);
/*
* The "-HMAC-" prefix is a special prefix recognized by
* test_openssl_engine.cpp
*/
SecretKey key1 = engine.getSecretKeyById(secret, "HmacSHA256");
SecretKey key1dupe = engine.getSecretKeyById(secret, "HmacSHA256");
/* Non-ENGINE-based SecretKey */
SecretKey key2 = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
/* The one that is ENGINE-based can't be equal to a non-ENGINE one. */
assertFalse(key1.equals(key2));
assertEquals(key1, key1dupe);
assertNull(key1.getFormat());
assertNull(key1.getEncoded());
assertEquals("RAW", key2.getFormat());
assertEquals(Arrays.toString(secret.getBytes()), Arrays.toString(key2.getEncoded()));
Mac mac1 = Mac.getInstance("HmacSHA256", p);
mac1.init(key1);
mac1.update(testString);
byte[] output1 = mac1.doFinal();
assertEquals(mac1.getMacLength(), output1.length);
Mac mac2 = Mac.getInstance("HmacSHA256", p);
mac2.init(key2);
mac2.update(testString);
byte[] output2 = mac2.doFinal();
assertEquals(Arrays.toString(output2), Arrays.toString(output1));
}
use of java.security.Provider in project robovm by robovm.
the class KeyStoreTest method test_KeyStore_getInstance.
public void test_KeyStore_getInstance() throws Exception {
String type = KeyStore.getDefaultType();
try {
KeyStore.getInstance(null);
fail(type);
} catch (NullPointerException expected) {
}
assertNotNull(KeyStore.getInstance(type));
String providerName = StandardNames.SECURITY_PROVIDER_NAME;
try {
KeyStore.getInstance(null, (String) null);
fail(type);
} catch (IllegalArgumentException expected) {
}
try {
KeyStore.getInstance(null, providerName);
fail(type);
} catch (Exception e) {
if (e.getClass() != NullPointerException.class && e.getClass() != KeyStoreException.class) {
throw e;
}
}
try {
KeyStore.getInstance(type, (String) null);
fail(type);
} catch (IllegalArgumentException expected) {
}
assertNotNull(KeyStore.getInstance(type, providerName));
Provider provider = Security.getProvider(providerName);
try {
KeyStore.getInstance(null, (Provider) null);
fail(type);
} catch (IllegalArgumentException expected) {
}
try {
KeyStore.getInstance(null, provider);
fail(type);
} catch (NullPointerException expected) {
}
try {
KeyStore.getInstance(type, (Provider) null);
fail(type);
} catch (IllegalArgumentException expected) {
}
assertNotNull(KeyStore.getInstance(type, provider));
}
Aggregations