title: How to encrypt a string using sha-1 by passing key?
body: <p>I'm trying to encrypt a string message to get same encrypted code for same string message in my app. How can i get the same encrypted code using same key?</p>
  
  <p>Below is my code. It is generating encrypted code but it does not match with that code which is generated at server</p>
  
  <pre><code> public  String SHAsum(String convertme) {
             MessageDigest md = null;
             byte[] data;
          try {
              md = MessageDigest.getInstance("SHA-1");
              data=convertme.getBytes("utf8");
              md.update(data);
              md.hashCode();
  
              //md.update( key.getBytes() );
              return new BigInteger( 1, md.digest() ).toString(16);
  
  
          } catch (NoSuchAlgorithmException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } //This could also be SHA1withDSA, no exception handling
          catch (UnsupportedEncodingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          return "";
  
          }
  </code></pre>
  
  <hr>
  
  <pre><code>String password="qqqqq"; 
  byte[] salt="guVoUubWwvniR2G0FgaC9".getBytes(); 
  String abc=""; 
  try 
    { 
      abc = getHash( password, salt); 
      System.out.println("Encypted password is --------------&gt;"+abc); 
    } 
  
  catch (NoSuchAlgorithmException e1) 
  {
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
  } 
  
  catch (UnsupportedEncodingException e1) 
  {
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
  }
  </code></pre>