DEV Community

Cover image for How to generate 11 char hash key for Sms Retriever?
Jyotishman Saikia
Jyotishman Saikia

Posted on

How to generate 11 char hash key for Sms Retriever?

11 digit unique hash string is the key used for auto verifying SMS. Google Play Services utilizes the hash string to figure out which check messages to send to your application. This unique hash can be different for different environments. For example, if an app is signed by a debug Keystore for development the hash will be different. Similarly, it will be different for production build if it is signed by a production Keystore. Also if the app is signed by app signing by Google Play again the hash will be different.
Let's get started on how to generate this hash

Solution 1 if your app is signed by google play

Step1- Go to play console -> Open app -> Release management -> App Signing -> Download Certificate .
Eg- A file will get download like deployment_cert.der

Step2- Convert the deployment_cert.der file to a .jks file, use below command

keytool -importcert -alias YOUR_ALIAS -file deployment_cert.der -keystore certificate.jks -storepass YOUR_PASSWORD

(replace alias with your alias name and YOUR_PASSWORD with your keystore password)

Step3- Once you enter the command, it will prompt like->
Trust this certificate? [no]: yes -> Certificate was added to Keystore

Step4- Now in terminal enter command

keytool -exportcert -alias YOUR_ALIAS -keystore certificate.jks | xxd -p | tr -d "[:space:]" | echo -n YOUR_PACKAGE `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

(replace alias with your alias name and YOUR_PASSWORD with your Keystore password)

Step5- Finally you will get the hash. For more original documentation refer- Click me

Step6- To know more on how to auto verify OTP on react native without asking permission read this article

Top comments (6)

Collapse
 
khajanizamuddin1 profile image
Khaja Nizamuddin

any other solution?
Can we generate the 11 digit hash key without Google signing?

Collapse
 
jyotishman profile image
Jyotishman Saikia

let me know what exact issue you are facing if I could help you?

Collapse
 
khajanizamuddin1 profile image
Khaja Nizamuddin

Hi, I am new to React Native/Expo
I'm implementing just the SMS retrieval code in React Native app following this article:
github.com/Bruno-Furtado/react-nat...

I need to get the 11 char hash key to add it to the end of my sms

So, 1 way to get it is by signing the app with Google (which is the easy way to store my keytool for multiple app I understand) as it requires registration fee to sign up for console
I'm wondering if there's any other way I can get the hash key
I'v run this to generate the keytool:

keytool -genkey -v -keystore app1sms.keystore -alias app1smsKey -keyalg RSA -keysize 2048 -validity 10000

I'm stuck with no clue what to do after this
Can you advise please

Thread Thread
 
jyotishman profile image
Jyotishman Saikia • Edited

Have you built your app using a signed key? If not you can generate your Keystore using the Android studio just with some clicks.
If you have already generated your Keystore than you can use the below command to generate your 11 digits unique hash key.

keytool -exportcert -alias my_alias -keystore path_to_my_keystore | xxd -p | tr -d "[:space:]" | echo -n my_app_package_name `cat` | shasum -a 256 | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Replace

my_alias with your alias name, path_to_my_keystore to the exact path of Keystore file and my_app_package_name with your application package name, eg- com.example

Finally, enter the password and 11 digit unique hash will be generated.

Thread Thread
 
iampapagray profile image
John Graham

After entering the password, nothing happens. No response and the prompt isn't returned. It seems its just stuck

Thread Thread
 
appi2393 profile image
Apurva Jain

keytool -exportcert -alias my_alias -keystore path_to_my_keystore | xxd -p | tr -d "[:space:]" | echo -n my_app_package_name 'cat' | shasum -a 256 | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Should work fine with above command. cat replaced with 'cat'