title: Need help translating some Java encryption to PHP
body: <p>I'm trying to port a "simple" string encryption algorithm from Java to PHP and it uses just enough obscure bits of specific Java libraries that I'm bashing my head against the wall. I'm hoping the SO community can help. Here's the Java:</p>
  
  <pre><code>public static String encode(String str) throws Exception {
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      md.reset();
      return (new BASE64Encoder()).encode(md.digest(str.getBytes("UTF-8")));
  }
  </code></pre>
  
  <p>Intuitively, I would think the equivalent in PHP would be something like:</p>
  
  <pre><code>base64_encode(sha1($str));
  </code></pre>
  
  <p>but this isn't working. I'm guessing this has something to do with the use of getBytes? </p>
  
  <hr>
  
  <p><strong>EDIT</strong>: Here's a couple examples of what I get:</p>
  
  <ul>
  <li>Java encode of "garden": <em>sa3lMQV/UcKZJHkzXQO3dK/etvo=</em> </li>
  <li><p>PHP encode of "garden": <em>YjFhZGU1MzEwNTdmNTFjMjk5MjQ3OTMzNWQwM2I3NzRhZmRlYjZmYQ==</em></p></li>
  <li><p>Java encode of "WhyJavaWhy": <em>oJTJIq6WJM8P9rFPnZdoyK/WBK4=</em></p></li>
  <li>PHP encode of "WhyJavaWhy": <em>YTA5NGM5MjJhZTk2MjRjZjBmZjZiMTRmOWQ5NzY4YzhhZmQ2MDRhZQ==</em></li>
  </ul>