title: SHA1 encryption and SHA1 to Hex in php
body: <p>I have two methods in Java and I want to do the same methods in php. I don't know absolutely nothing in php. How can I do it?</p>
  
  <p>Method 1:</p>
  
  <pre><code>public static String encyptPassword (String in) throws UnsupportedEncodingException, NoSuchAlgorithmException{
      byte[] bytes=in.getBytes("UTF-8");
      MessageDigest md=MessageDigest.getInstance(MGF1ParameterSpec.SHA1.getDigestAlgorithm());
      md.update(bytes);
      byte[] digest=md.digest();
      return toHex(digest);
  }
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>public static String toHex(byte[] bytes) {
      BigInteger bi = new BigInteger(1, bytes);
      return String.format("%0" + (bytes.length &lt;&lt; 1) + "x", bi);
  }
  </code></pre>
  
  <p>The methods (function?) in php must have the same result as in java, because it's <strong>hashing</strong> passwords for a working and online login system.</p>
  
  <p>I'm trying it about 3 hours, but I can't do it or found a solution. I think I read all posts on Stack. Can you help me? Thanks.</p>