compute SHA-1 Hash : SHA « Security « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Security » SHA 
compute SHA-1 Hash
 

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

public class CryptoUtils {
  public static String computeHash(final String xthrows 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[i0xff;
      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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.