title: Triple DES with MD5 hash in ECB mode. C# to Java Code Conversion
body: <p>I am trying to covert a c# encryption method to java. It is Triple DES with MD5 hash in ECB mode and I am having a hard time finding the java equivalent. The hashes do not match when I try to run them</p>
  <p>Below is the c# code</p>
  <pre><code> public string Encrypt(string value, string key)
      {
          string encrypted;
  
          var hashmd5 = new MD5CryptoServiceProvider();
          var des = new TripleDESCryptoServiceProvider();
          des.Key = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
          des.Mode = CipherMode.ECB; //CBC, CFB
          var buff = ASCIIEncoding.ASCII.GetBytes(value);
          encrypted = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(buff, 0, buff.Length));
  
          return encrypted;
      }
  </code></pre>
  <p>Here is the Java Code</p>
  <pre><code> public String encryptSession (String session, String sessionEncryptionKey) throws Exception {
      MessageDigest md = MessageDigest.getInstance(&quot;MD5&quot;);
      byte[] hash = EncodingUtils.getAsciiBytes(sessionEncryptionKey);
      byte[] digestOfPassword = md.digest(hash);
      byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
      for (int j = 0, k = 16; j &lt; 8;) {
          keyBytes[k++] = keyBytes[j++];
      }
  
      SecretKey key = new SecretKeySpec(keyBytes, &quot;DESede&quot;);
      Cipher cipher = Cipher.getInstance(&quot;DESede/ECB/PKCS5Padding&quot;);
      cipher.init(Cipher.ENCRYPT_MODE, key);
      byte[] sessionBytes = EncodingUtils.getAsciiBytes(session);
  
  
      byte[] buf = cipher.doFinal(sessionBytes);
      byte[] base64Bytes = Base64.getEncoder().encode(buf);
      String base64EncryptedString = new String(base64Bytes);
  
      return base64EncryptedString;
  }
  </code></pre>