public static String [ ] getHashKeys ( Activity context ) throws NoSuchAlgorithmException { PackageInfo packageInfo = null ; String [ ] keys = null ; try { packageInfo = context . getPackageManager ( ) . getPackageInfo ( context . getPackageName ( ) , PackageManager . GET_SIGNATURES ) ; if ( packageInfo != null && packageInfo . signatures != null && packageInfo . signatures . length > 0 ) { keys = new String [ packageInfo . signatures . length ] ; for ( int i = 0 ; i < packageInfo . signatures . length ; i ++ ) { Signature signature = packageInfo . signatures [ i ] ; MessageDigest md = MessageDigest . getInstance ( "SHA1" ) ; md . update ( signature . toByteArray ( ) ) ; String hash = new String ( Base64 . encode ( md . digest ( ) , 0 ) ) ; keys [ i ] = hash ; } } } catch ( PackageManager . NameNotFoundException e ) { e . printStackTrace ( ) ; } return keys ; }
Returns the hash key used to authenticate this application with Facebook . Useful for debugging .