title: Why SHA1 is slower than AES? JCE
body: <p>I'm currently building applications, which uses crypto primitives. For encryption and hashing I use javax.crypto and java.security packages. I did some benchmarking and it turned out, that ECB-AES-128 is faster than SHA1.
  Code that I used for AES testing:</p>
  
  <pre><code>    byte[] key = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
      byte[] data = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  
      SecretKeySpec encryptionKey = new SecretKeySpec(key, "AES");
      Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
      cipher.init(Cipher.ENCRYPT_MODE, encryptionKey);
  
      long start = System.currentTimeMillis();
      for (int i=0; i&lt;10000000; i++)
      {
          cipher.doFinal(data);
      }
      long end = System.currentTimeMillis();      
  
      System.out.println("took: "+ (end-start));
  </code></pre>
  
  <p>For hashing </p>
  
  <pre><code>    MessageDigest md = MessageDigest.getInstance("SHA-1");
      byte[] data = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  
  
      long start = System.currentTimeMillis();
      for (int i=0; i&lt;10000000; i++)
      {
          md.digest(data);
      }
      long end = System.currentTimeMillis();
  
      System.out.println("took:" + (end-start));
  </code></pre>
  
  <p>Encryption time takes : ~4sec.
  Hashing time takes: ~10sec.
  Config: Core i5 3570-3.4Ghz, 8Gb RAM (not sure , whether it matters) </p>
  
  <p>Why encryption takes less time than hashing? Hash functions should be way faster. Am I doing something wrong? 
  Thank you</p>