How to generate 11 char hash key for Sms Retriever?

Jyotishman Saikia - Jun 30 '20 - - Dev Community

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

. . . . . . . . . . . . . . . . . . . . .