title: Triple DES Algorithm in Android JAVA
body: <p>I am new to Android-Java. I have below function in C# for Encryption (Triple DES)</p>
  
  <pre><code>public string Encrypt(string data)
      {
          try
          {
              if (!string.IsNullOrEmpty(data))
              {
                  //byte[] keyArray;
                  byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(data);
                  //System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
  
                  byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
                  TripleDESCryptoServiceProvider CryptDesECB = new TripleDESCryptoServiceProvider();
                  CryptDesECB.Key = keyArray;
                  CryptDesECB.Mode = CipherMode.ECB;
                  CryptDesECB.Padding = PaddingMode.PKCS7;
                  ICryptoTransform cTransform = CryptDesECB.CreateEncryptor();
                  byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                  CryptDesECB.Clear();
                  return Convert.ToBase64String(resultArray, 0, resultArray.Length);
              }
              return string.Empty;
          }
          catch (Exception)
          {
              return string.Empty;
          }
      }
  </code></pre>
  
  <p>I have tried below code for having same Encryption function in Android platform:</p>
  
  <pre><code>public static String EncryptText(String message) throws Exception {
          MessageDigest md = MessageDigest.getInstance("SHA-1");
          byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
          byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
  
          SecretKey key = new SecretKeySpec(keyBytes, "DESede");
          Cipher cipher = Cipher.getInstance("DESede");
          cipher.init(Cipher.ENCRYPT_MODE, key);
  
          byte[] plainTextBytes = message.getBytes("utf-8");
          byte[] buf = cipher.doFinal(plainTextBytes);
          byte [] base64Bytes = Base64.encode(buf,Base64.DEFAULT);
          String base64EncryptedString = new String(base64Bytes);
  
          return base64EncryptedString;
  }
  </code></pre>
  
  <p>But, the encryption result is different on both platforms? If anyone can help me in pointing the issue in Android function.</p>
  
  <p>Thanks in advance.</p>