3

I am using twilio sdk to integrate sms verification with my android app, twilio asks me to register hash signature of my app and non of ways to generate hash signature worked, always says it is invalid hash signature this is the path that twilio wants the hash signature

diagram here

MatejMecka
  • 1,448
  • 2
  • 24
  • 37

3 Answers3

6

User below command in terminal of android studio to generate release key hash

keytool -exportcert -alias [aliasname] -keystore [your app keystore path] | openssl sha1 -binary | openssl base64

And below code in your project to get development key hash

try {
    android.content.pm.PackageInfo info = getPackageManager().getPackageInfo(
            "com.apps.sonictonic",
            android.content.pm.PackageManager.GET_SIGNATURES);
    for (android.content.pm.Signature signature : info.signatures) {
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        android.util.Log.d("KeyHash", "KeyHash:" + android.util.Base64.encodeToString(md.digest(),
                android.util.Base64.DEFAULT));

    }
} catch (android.content.pm.PackageManager.NameNotFoundException e) {

} catch (java.security.NoSuchAlgorithmException e) {

}
Zealous System
  • 2,080
  • 11
  • 22
1

Call this method in your Activity onCreate() and Search your key in logcat using key "HashKey"

public static void printHashKey(Context pContext) {
    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String hashKey = new String(Base64.encode(md.digest(), 0));
            Log.d("HashKey", "printHashKey() Hash Key: " + hashKey);
        }
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "printHashKey()", e);
    } catch (Exception e) {
        Log.e(TAG, "printHashKey()", e);
    }
}
0

If you have opted your app into Google Play managed signing, then you need to use a different set of steps to get the correct signature hash.

How to configure Signature Hash with Google Play Signing · Issue #1550 · AzureAD/microsoft-authentication-library-for-android

dragon788
  • 3,583
  • 1
  • 40
  • 49