Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating hash string for google sms retriever api - 'xxd' is not recognized as an internal or external command

After the google's new policy regarding SMS and Call log permissions, I am trying to implement SMS retriever API for my android application. The tutorial seems easy but I found a problem while creating/generating hash for the same.

When I type

keytool -alias MyAndroidKey -exportcert -keystore MyProduction.keystore | xxd -p | tr -d "[:space:]"

OR

keytool -exportcert -alias MyAndroidKey -keystore MyProductionKeys.keystore | xxd -p | tr -d "[:space:]" | echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

It says:

'xxd' is not recognized as an internal or external command,
operable program or batch file.

'tr' is not recognized as an internal or external command,
operable program or batch file.

There are no clarification available on https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string page

Thanks.

like image 699
Khan Sharukh Avatar asked Jan 16 '19 06:01

Khan Sharukh


People also ask

How do I get the hash string of an SMS signature?

Alternatively, you can get your app's hash string with the AppSignatureHelper class from the SMS retriever sample app. However, if you use the helper class, be sure to remove it from your app after you get the hash string. Do not use hash strings dynamically computed on the client in your verification messages.

How to use the SMS Retriever API?

The SMS Retriever API is available only on Android devices with Play services version 10.2 and newer. When a client’s phone receives any message containing a unique string, SMS Retriever API will broadcast the message with SmsRetriever.SMS_RETRIEVED_ACTION intent. Then, we should use a broadcast receiver to receive the verification message.

What is 1111 digit unique hash string used for?

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.

How to generate hash string in Google Play Services?

Google Play services uses the hash string to determine which verification messages to send to your app. The hash string is made of your app’s package name and your app’s public key certificate. To generate the hash string: Let’s create a class named is AppSignatureHelper and paste the below code. This is the simplest way to get hash string.


3 Answers

Finally I managed to get hash key for using SMS retriever API - Android.

Steps I followed.

  1. I was using Git so it was installed on my machine. Head over to C:\Program Files\Git\usr\bin and I see that it has xxd.exe and tr.exe which was my requirement.

  2. So I added the environment variable to Path > New > C:\Program Files\Git\usr\bin

  3. Restart the cmd with administrator privileges. xxd and tr command started working.

Hope this will help others as google has stopped CALL_LOG, READ_SMS permission.

Cheers.

---------------------UPDATE-----------------------

I found an another good answer here.

Please follow the link it gives a step by step tut for creating the hash key.

I followed this because after publishing app to play store the generated hash key doesn't work any more.

How to generate 11 char hash key for Sms Retriever with Google App signing

Hope it will help someone!

like image 74
Khan Sharukh Avatar answered Sep 21 '22 03:09

Khan Sharukh


[UPDATED for windows]

# xxd
C:\Program Files\Git\usr\bin\xxd
# tr
C:\Program Files\Git\usr\bin\tr
# base64
C:\Program Files\Git\usr\bin\base64

The whole commands become

keytool -exportcert -alias YOUR_ALIAS -keystore certificate.jks | "C:\Program Files\Git\usr\bin\xxd" -p |"C:\Program Files\Git\usr\bin\tr" -d "[:space:]" | echo -n PACKAGE_NAME `cat` | "C:\Program Files\Git\usr\bin\sha256sum" | "C:\Program Files\Git\usr\bin\tr" -d "[:space:]-" | "C:\Program Files\Git\usr\bin\xxd" -r -p | "C:\Program Files\Git\usr\bin\base64" | "C:\Program Files\Git\usr\bin\cut" -c1-11
like image 41
Akash Sharma Avatar answered Sep 24 '22 03:09

Akash Sharma


In Window, if you are using SourceTree you will search with xxd.exe keyword or find it with C:\Users\your_user_name\AppData\Local\Atlassian\SourceTree\git_local\usr\bin path.

Example: keytool -alias MyKey -exportcert -keystore MyKey.keystore | C:\Users\your_user_name\AppData\Local\Atlassian\SourceTree\git_local\usr\bin\xxd -p | C:\Users\your_user_name\AppData\Local\Atlassian\SourceTree\git_local\usr\bin\tr -d "[:space:]"

You can download here

like image 21
John Le Avatar answered Sep 24 '22 03:09

John Le