/** * Test for <code>SecretKeyFactory</code> constructor * Assertion: returns SecretKeyFactory object */ public void testSecretKeyFactory01() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException { if (!DEFSupported) { fail(NotSupportMsg); return; } SecretKeyFactorySpi spi = new MySecretKeyFactorySpi(); SecretKeyFactory secKF = new mySecretKeyFactory(spi, defaultProvider, defaultAlgorithm); assertEquals("Incorrect algorithm", secKF.getAlgorithm(), defaultAlgorithm); assertEquals("Incorrect provider", secKF.getProvider(), defaultProvider); assertNull("Incorrect result", secKF.generateSecret(null)); assertNull("Incorrect result", secKF.getKeySpec(null, null)); assertNull("Incorrect result", secKF.translateKey(null)); secKF = new mySecretKeyFactory(null, null, null); assertNull("Algorithm must be null", secKF.getAlgorithm()); assertNull("Provider must be null", secKF.getProvider()); try { secKF.translateKey(null); fail("NullPointerException must be thrown"); } catch (NullPointerException e) { } }
/** * Test for <code>SecretKeyFactory</code> constructor * Assertion: returns SecretKeyFactory object */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "SecretKeyFactory", args = {javax.crypto.SecretKeyFactorySpi.class, java.security.Provider.class, java.lang.String.class} ) public void testSecretKeyFactory01() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException { if (!DEFSupported) { fail(NotSupportMsg); return; } SecretKeyFactorySpi spi = new MySecretKeyFactorySpi(); SecretKeyFactory secKF = new mySecretKeyFactory(spi, defaultProvider, defaultAlgorithm); assertEquals("Incorrect algorithm", secKF.getAlgorithm(), defaultAlgorithm); assertEquals("Incorrect provider", secKF.getProvider(), defaultProvider); assertNull("Incorrect result", secKF.generateSecret(null)); assertNull("Incorrect result", secKF.getKeySpec(null, null)); assertNull("Incorrect result", secKF.translateKey(null)); secKF = new mySecretKeyFactory(null, null, null); assertNull("Algorithm must be null", secKF.getAlgorithm()); assertNull("Provider must be null", secKF.getProvider()); try { secKF.translateKey(null); fail("NullPointerException must be thrown"); } catch (NullPointerException e) { } }
@TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "translateKey", args = {javax.crypto.SecretKey.class} ), @TestTargetNew( level = TestLevel.COMPLETE, notes = "", clazz = SecretKeyFactorySpi.class, method = "engineTranslateKey", args = {javax.crypto.SecretKey.class} ) }) public void test_translateKeyLjavax_crypto_SecretKey() throws NoSuchAlgorithmException, InvalidKeyException { KeyGenerator kg = null; Key key = null; SecretKeyFactory secKF = null; for (int i = 0; i < validValues.length; i++) { secKF = SecretKeyFactory .getInstance(validValues[i]); assertNotNull(secKF.getProvider()); kg = KeyGenerator.getInstance(secKF.getAlgorithm()); kg.init(new SecureRandom()); key = kg.generateKey(); secKF.translateKey((SecretKey) key); } try { secKF.translateKey(null); fail("InvalidKeyException expected"); } catch (InvalidKeyException e) { //expected } }
protected AsyncSecretKeyFactory(final SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm) { super(keyFacSpi, provider, algorithm); if (keyFacSpi instanceof AsyncSecretKeyFactorySpi) { asyncSpi = (AsyncSecretKeyFactorySpi) keyFacSpi; return; } }
public static final AsyncSecretKeyFactory getAsyncInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) throw new IllegalArgumentException(); Provider.Service service = provider.getService("SecretKeyFactory", algorithm); if (service != null) { return new AsyncSecretKeyFactory( (SecretKeyFactorySpi) service.newInstance(null), provider, algorithm); } throw new NoSuchAlgorithmException("Invalid secret key factory: " + algorithm); }
public SecretKeyFactorySpi create(Object constructorParam) { try { return Adaptor.adapt(type.newInstance(), SecretKeyFactorySpi.class); } catch (Exception e) { throw new IllegalArgumentException("Invalid type: " + type, e); } }
/** * Factory method to get the proper factory class. The SunJCE provider * appears to have its own classloader so simply adding the values (as * above) does not work and the classes are not found. Hence the reflection * work below. * * @param algorithm * @return * @throws NoSuchAlgorithmException */ @SuppressWarnings("unchecked") public static SecretKeyFactory getSecretKeyFactory(String algorithm) throws NoSuchAlgorithmException { try { Class<SecretKeyFactorySpi> clazz = (Class<SecretKeyFactorySpi>) Class.forName((String) provider.get("SecretKeyFactory." + algorithm)); SecretKeyFactorySpi spi = clazz.newInstance(); Constructor<SecretKeyFactory> c = SecretKeyFactory.class.getDeclaredConstructor(SecretKeyFactorySpi.class, Provider.class, String.class); c.setAccessible(true); return c.newInstance(spi, provider, algorithm); } catch (Exception e) { throw new NoSuchAlgorithmException(e); } }
/** @ar.org.fitc.spec_ref */ protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm) { this.secretKeyFactorySpi = keyFacSpi; this.provider = provider; this.algorithm = algorithm; }
protected Mock_SecretKeyFactory(SecretKeyFactorySpi arg0, Provider arg1, String arg2) { super(arg0, arg1, arg2); }
public mySecretKeyFactory(SecretKeyFactorySpi spi, Provider prov, String alg) { super(spi, prov, alg); }
public SecretKeyFactorySpiFactory(Class<? extends javax.crypto.SecretKeyFactorySpi> type) { this.type = type; }
/** * It's used as a factory method * * @param algorithm * the algorithm * @param provider * the provider * @return a new SecretKeyFactory object * @throws NoSuchAlgorithmException * if the specified algorithm is not available in the default * package or any of the others providers that were searched */ private static final SecretKeyFactory newInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { Service service = Util.getService(Types.SECRET_KEY_FACTORY, algorithm, provider); if (service == null) { throw new NoSuchAlgorithmException("No such algorithm: " + algorithm); } return new SecretKeyFactory((SecretKeyFactorySpi) service .newInstance(null), service.getProvider(), algorithm); }