title: Android AES decryption returning rare characters V2.0
body: <p>Recently i've post a question about this topic but the thing turns a little weird when i tried to decrypt an AES String that was encoded on UTF8 </p>
  
  <p>In the following lines i read the String AES encrypted wich returns the following String: RnLObq9hdUDGp9S2pxC1qjQXekuf9g6i/5bQfKilYn4=</p>
  
  <pre><code>public static final String AesKey256 ="ZzRtNDNuY3J5cHRrM3kuLi4=";
  //This reads the String and stores on res.getContents()
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      IntentResult res= IntentIntegrator.parseActivityResult(requestCode, resultCode,data);
      if(res!=null){
          if (res.getContents() == null) {
              Toast.makeText(this,"Captura cancelada",Toast.LENGTH_SHORT).show();
          }else{
              try {
                  String cadena= decrypt(res.getContents());
                  out.setText(cadena);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  
  }
  //provide the res.getContents() to decrypt method, wich its the String i've recently read
   private String decrypt(String cadena)throws Exception{
      SecretKeySpec keySpec= generateKey(AesKey256); //HERE
      Cipher c= Cipher.getInstance(AES_MODE);
      c.init(Cipher.DECRYPT_MODE,keySpec);
      byte[] decodedValue= Base64.decode(cadena, Base64.DEFAULT);
      byte[] decValue= c.doFinal(decodedValue);/* c.doFinal(decodedValue);*/
      String decryptedValue= new String((decValue), "UTF-8");
      return decryptedValue;
  }
   private SecretKeySpec generateKey(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
      final MessageDigest digest= MessageDigest.getInstance("SHA-256");
      byte[] bytes= password.getBytes("UTF-8");
      digest.update(bytes,0,bytes.length);
      byte[] key= digest.digest();
      SecretKeySpec secretKeySpec= new SecretKeySpec(key, "AES");
      return secretKeySpec;
  }
  </code></pre>
  
  <p>I am only using the decryption method but it still returning this characters: 
  <a href="https://i.stack.imgur.com/eamx9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eamx9.png" alt="this shows after read the string"></a></p>
  
  <p>i've spent hours looking for a solution, but nothing works for now... hope someone can give me a hand!</p>
  
  <p>Best Regards!</p>
  
  <p>EDIT
  THIS IS HOW IT WAS ENCRYPTED IN C#</p>
  
  <pre><code>private const string AesIV256 = "IVFBWjJXU1gjRURDNFJGVg==";
          private const string AesKey256 = "ZzRtNDNuY3J5cHRrM3kuLi4=";
  
          public static string Encrypt(string text)
          {
              var sToEncrypt = text;
              var rj = new RijndaelManaged()
              {
                  Padding = PaddingMode.Zeros,
                  Mode = CipherMode.ECB,
                  KeySize = 256,
                  BlockSize = 256,
              };
  
              var key = Convert.FromBase64String(AesKey256);
              var IV = Convert.FromBase64String(AesIV256);
  
              var encryptor = rj.CreateEncryptor(key, IV);
  
              var msEncrypt = new MemoryStream();
              var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
  
              var toEncrypt = Encoding.UTF8.GetBytes(sToEncrypt);
  
              csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
              csEncrypt.FlushFinalBlock();
  
              var encrypted = msEncrypt.ToArray();
  
              return (Convert.ToBase64String(encrypted));
          }
  </code></pre>