-2

I can get SHA-1 fingerprint through cmd in windows or from eclipse IDE, but I want to use SHA-1 fingerprint in my application, so I want to know how to generate SHA-1 fingerprint through code?

Ikarus
  • 1,169
  • 4
  • 14
  • 28
  • Fingerprint of android application, you can see it in eclipse: window -> preference -> android -> build. – Ikarus Jul 21 '14 at 18:47

1 Answers1

0
try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.hellofacebook", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }