-
-
Save anonymous/a60f61816b758e43bcb614f2679557bd to your computer and use it in GitHub Desktop.
Pega hash para o cadastro de app no facebook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package br.com.consultoriadigital.insights.core; | |
| import android.content.Context; | |
| import android.content.pm.PackageInfo; | |
| import android.content.pm.PackageManager; | |
| import android.content.pm.Signature; | |
| import android.util.Base64; | |
| import android.util.Log; | |
| import java.security.MessageDigest; | |
| import java.security.NoSuchAlgorithmException; | |
| /** | |
| * Created by Thiago on 05/06/2016. | |
| */ | |
| public class UtilsPackages { | |
| public static String getSignature(Context context) { | |
| PackageInfo info; | |
| String hash = null; | |
| try { | |
| info = context.getPackageManager().getPackageInfo( | |
| context.getPackageName(), PackageManager.GET_SIGNATURES); | |
| for (Signature signature : info.signatures) { | |
| MessageDigest md; | |
| md = MessageDigest.getInstance("SHA1"); | |
| md.update(signature.toByteArray()); | |
| hash = new String(Base64.encode(md.digest(), 0)); | |
| Log.e("hash key", hash); | |
| } | |
| } catch (PackageManager.NameNotFoundException e) { | |
| Log.e("name not found", e.toString()); | |
| } catch (NoSuchAlgorithmException e) { | |
| Log.e("no such an algorithm", e.toString()); | |
| } catch (Exception e) { | |
| Log.e("exception", e.toString()); | |
| } | |
| return hash; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment