title: junit java test for function with AES encryption(javax.crypt library) not working. Android device
body: <p>I start testing my Android application with jUnit, And i test function with javax.crypto library.</p>
  
  <p>I try <strong>Cipher.init(Cipher.ENCRYPT_MODE, key, spec);</strong> function.
  With simple android debbuger everything works fine, but with junit test I get an error(InvalidKeyException),I do not understand why?. Feeling so this function do not get my date. Or maybe junit do not have access for this javax.crypto library?</p>
  
  <p>My full code is:</p>
  
  <pre><code>public void testEncryptionKey(){
      MessageDigest digest = null;
      try {
  
          digest = MessageDigest.getInstance("SHA-256");
          digest.update("Hello".getBytes("UTF-8"));
          byte[] keyBytes = new byte[32];
          keyBytes = digest.digest();
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          SecretKeySpec key = new SecretKeySpec(keyBytes,"AES");
          AlgorithmParameterSpec spec = getIV();
          cipher.init(Cipher.ENCRYPT_MODE, key, spec);
  
      } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (InvalidAlgorithmParameterException e) {
          e.printStackTrace();
      } catch (NoSuchPaddingException e) {
          e.printStackTrace();
      } catch (InvalidKeyException e) {
          e.printStackTrace();
      }
  }
  
  public AlgorithmParameterSpec getIV()
  {
      byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      IvParameterSpec ivParameterSpec;
      ivParameterSpec = new IvParameterSpec(iv);
      byte[] ivv = ivParameterSpec.getIV();
      return ivParameterSpec;
  }
  </code></pre>
  
  <p>Here is screenshot with the error:</p>
  
  <p><a href="https://i.stack.imgur.com/5EpHj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5EpHj.png" alt="error"></a></p>