Reputation: 33
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
Upvotes: 3
Views: 13533
Reputation: 3931
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.
Upvotes: 0
Reputation: 2324
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) {
}
Upvotes: 7
Reputation: 21
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);
}
}
Upvotes: 1