public void test_initWithKeyAlgorithmParameterSpecSecureRandom() throws Exception {
  AlgorithmParameterSpec ap=new IvParameterSpec(IV);
  Cipher cipher=Cipher.getInstance(ALGORITHM_3DES + "/CBC/PKCS5Padding");
  cipher.init(Cipher.ENCRYPT_MODE,CIPHER_KEY_3DES,ap,new SecureRandom());
  byte[] cipherIV=cipher.getIV();
  assertTrue("IVs differ",Arrays.equals(cipherIV,IV));
  cipher=Cipher.getInstance("DES/CBC/NoPadding");
  try {
    cipher.init(Cipher.ENCRYPT_MODE,CIPHER_KEY_3DES,ap,new SecureRandom());
    fail();
  }
 catch (  InvalidKeyException expected) {
  }
  cipher=Cipher.getInstance("DES/CBC/NoPadding");
  ap=new RSAKeyGenParameterSpec(10,new BigInteger("10"));
  try {
    cipher.init(Cipher.ENCRYPT_MODE,CIPHER_KEY_DES,ap,new SecureRandom());
    fail();
  }
 catch (  InvalidAlgorithmParameterException expected) {
  }
}

public void test_initWithKeyAlgorithmParameterSpecSecureRandom ( ) throws Exception { AlgorithmParameterSpec ap = new IvParameterSpec ( IV ) ; Cipher cipher = Cipher . getInstance ( ALGORITHM_3DES + "/CBC/PKCS5Padding" ) ; cipher . init ( Cipher . ENCRYPT_MODE , CIPHER_KEY_3DES , ap , new SecureRandom ( ) ) ; byte [ ] cipherIV = cipher . getIV ( ) ; assertTrue ( "IVs differ" , Arrays . equals ( cipherIV , IV ) ) ; cipher = Cipher . getInstance ( "DES/CBC/NoPadding" ) ; try { cipher . init ( Cipher . ENCRYPT_MODE , CIPHER_KEY_3DES , ap , new SecureRandom ( ) ) ; fail ( ) ; } catch ( InvalidKeyException expected ) { } cipher = Cipher . getInstance ( "DES/CBC/NoPadding" ) ; ap = new RSAKeyGenParameterSpec ( 10 , new BigInteger ( "10" ) ) ; try { cipher . init ( Cipher . ENCRYPT_MODE , CIPHER_KEY_DES , ap , new SecureRandom ( ) ) ; fail ( ) ; } catch ( InvalidAlgorithmParameterException expected ) { } }
javax . crypto . cipher # init ( int , java . security . key , java . security . spec . algorithmparameterspec , java . security . securerandom )
