compute SHA-1 Hash : SHA « Security « Android






compute SHA-1 Hash

 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CryptoUtils {
  public static String computeHash(final String x) throws NoSuchAlgorithmException
  {
    MessageDigest d = null;
    d = MessageDigest.getInstance("SHA-1");
    d.reset();
    d.update(x.getBytes());
    return  byteArrayToHexString(d.digest());
  }

  private static String byteArrayToHexString(final byte[] b){
    final StringBuffer sb = new StringBuffer(b.length * 2);
    for (int i = 0; i < b.length; i++){
      final int v = b[i] & 0xff;
      if (v < 16) {
        sb.append('0');
      }
      sb.append(Integer.toHexString(v));
    }
    return sb.toString().toUpperCase();
  }

}

   
  








Related examples in the same category

1.SHA-1 string
2.hmac Sha1 Digest
3.Sha1 hashes based on a given String
4.SHA1 Utils
5.Using SharedPreferences to store password
6.Using SharedPreferences
7.Drawing Shapes
8.Animated wallpaper draws a rotating wireframe shape with a choice of 2 shapes
9.Animation: shake
10.Get reference from SharedPreferences
11.Glutes shape
12.Reshaping Arabic Sentences and Text Utilities to deal with Arabic
13.Save SharedPreferences
14.Save value to SharedPreferences
15.SharedPreferences Set and get value
16.Compute the SHA-1 hash of the given byte array