use of java.security.NoSuchAlgorithmException in project j2objc by google.
the class AlgorithmParametersTest method test_getInstanceLjava_lang_StringLjava_lang_String.
/**
* java.security.AlgorithmParameters#getInstance(String, String)
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String() {
String[] alg = { "", "qwertyu", "!@#$%^&*()" };
String[] prv = { "", null };
String[] prv1 = { "1234567890", "qwertyu", "!@#$%^&*()" };
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", "MyProvider");
checkUnititialized(ap);
ap.init(new byte[6]);
checkAP(ap, p);
} catch (Exception e) {
fail("Unexpected exception");
}
for (int i = 0; i < alg.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(alg[i], "MyProvider");
fail("NoSuchAlgorithmException was not thrown for parameter " + alg[i]);
} catch (NoSuchAlgorithmException nsae) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown for " + alg[i]);
}
}
for (int i = 0; i < prv.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv[i]);
fail("IllegalArgumentException was not thrown for parameter " + prv[i]);
} catch (IllegalArgumentException iae) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown for " + prv[i]);
}
}
for (int i = 0; i < prv1.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv1[i]);
fail("NoSuchProviderException was not thrown for parameter " + prv1[i]);
} catch (NoSuchProviderException nspe) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown for " + prv1[i]);
}
}
}
use of java.security.NoSuchAlgorithmException in project j2objc by google.
the class KeyFactoryTest method testTranslateKey.
@SuppressWarnings("unchecked")
public void testTranslateKey() {
KeyFactory factory = null;
try {
factory = KeyFactory.getInstance(TEST_KEYFACTORY_NAME);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
assertNotNull(factory);
{
Key[] keys = { new TestPrivateKey(), new TestPublicKey() };
Class[] translated = { TestPublicKey.class, TestPrivateKey.class };
for (int i = 0; i < keys.length; i++) {
Key key = keys[i];
Class translate = translated[i];
try {
Key translateKey = factory.translateKey(key);
assertNotNull(translateKey);
assertEquals(translate, translateKey.getClass());
} catch (InvalidKeyException e) {
fail("unexpected exception: " + e);
}
}
}
{
Key[] keys = { new AnotherKey(), null };
Class[] exceptions = { InvalidKeyException.class, NullPointerException.class };
for (int i = 0; i < keys.length; i++) {
Key key = keys[i];
String message = "translateKey(" + (key == null ? "null" : key.toString()) + ")";
exceptionThrown = false;
try {
factory.translateKey(key);
} catch (Exception e) {
checkException(message, e, exceptions[i]);
} finally {
checkException(message, null, exceptions[i]);
}
}
}
}
use of java.security.NoSuchAlgorithmException in project j2objc by google.
the class AlgorithmParametersTest method test_getInstanceLjava_lang_String.
/**
* java.security.AlgorithmParameters#getInstance(String)
*/
public void test_getInstanceLjava_lang_String() {
String[] str = { "", "qwertyu", "!@#$%^&*()" };
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC");
checkUnititialized(ap);
ap.init(new MyAlgorithmParameterSpec());
checkAP(ap, p);
} catch (Exception e) {
fail("Unexpected exception");
}
for (int i = 0; i < str.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(str[i]);
fail("NoSuchAlgorithmException was not thrown for parameter " + str[i]);
} catch (NoSuchAlgorithmException nsae) {
//expected
}
}
}
use of java.security.NoSuchAlgorithmException in project j2objc by google.
the class SecureRandom2Test method testGetProvider.
public void testGetProvider() {
SecureRandom sr1 = new SecureRandom();
assertNotNull(sr1.getProvider());
SecureRandom sr2 = new SecureRandom(SEED_BYTES);
assertNotNull(sr2.getProvider());
MyProvider p = new MyProvider();
MySecureRandom sr3 = new MySecureRandom(new MySecureRandomSpi(), p);
assertEquals(p, sr3.getProvider());
try {
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
assertNotNull(random.getProvider());
} catch (NoSuchAlgorithmException e) {
fail("Unexpected NoSuchAlgorithmException");
}
}
use of java.security.NoSuchAlgorithmException in project keywhiz by square.
the class Hkdf method initMac.
private Mac initMac(SecretKey key) {
Mac mac;
try {
mac = Mac.getInstance(hash.getAlgorithm(), provider);
mac.init(key);
return mac;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (InvalidKeyException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations