Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate hash signature?

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

like image 298
Muhammad Noamany Avatar asked Jan 18 '26 11:01

Muhammad Noamany


2 Answers

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) {

}
like image 55
Zealous System Avatar answered Jan 21 '26 03:01

Zealous System


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);
    }
}
like image 31
Rohit Kumar Avatar answered Jan 21 '26 01:01

Rohit Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!