react-native-sms-retriever
react-native-sms-retriever copied to clipboard
Problems generating the Hash and using the lib
Environment
- React Native Version: 0.64.3
- Platform: Android
- OS Version: Fedora 35
- react-native-sms-retriever version: 1.1.1
Description
Everyone is having problems creating the hash and using the lib and not getting any help
Solution
I finally got it after many tries
timeout error or event.message == null: Apparently what causes this is the incorrect hash. I found it by debugging the example app, as the repo owner provided the right hash. I was using the tools and comparing until it was the same.
I had a lot of trouble finding the right way to hash it. The way in the official Google doc is complicated, most (if not all) the scripts that generate the hash give a false feeling that everything is OK, it gives you a different hash depending on the information you pass, as Password or Keystore Alias.
How I solved: I used the following script
#!/usr/bin/env bash
error() { printf "%s\n" "$1" >&2; exit 1; }
command -v keytool &> /dev/null || error "Command 'keytool' not found"
(( $# >= 2 )) || error "Usage: $(basename "$0") <file.der | file.keystore alias> appId"
file=$1
[[ -r $file ]] || error "'$file' doesn't exist or isn't readable"
if [[ $file = *.keystore ]]; then
keystore=$file
alias=$2
[[ $3 ]] || error "Missing application id argument"
app_id=$3
elif [[ $file = *.der ]]; then
trap 'code=$?; rm -rf -- "$tmp_folder"; exit "$code"' EXIT SIGINT SIGQUIT SIGTERM
tmp_folder=$(mktemp -d)
keystore=$tmp_folder/tmp.keystore
alias=temp
app_id=$2
keytool -importcert -file "$file" -keystore "$keystore" -alias "$alias"
else
error "'$file' needs to be of type *.der or *.keystore"
fi
keytool -exportcert -keystore "$keystore" -alias "$alias" | xxd -p | tr -d "[:space:]" | printf '%s %s' "$app_id" "$(cat)" | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11
Save with .sh extension
Run
chmod u+x ./<name>.sh
to enable execution
mode of use
./key2.sh <caminho para .keystore> <key alias> <app package name>
Exemplo:
./key2.sh ./ps-deploy.keystore myalias br.com.example.app
Enter the store password when prompted
This will give the correct hash
Let's go to some points to be clarified
.jks signing key
Apps created with Expo can come with the .jks key
In my case I transformed the key into .keystore
To do this just copy and rename the file changing its extension from .jks to .keystore Ex:
cp ./key.jks ./newKey.keystore
The app is signed with different keys in some modes
In debug mode the app is signed with the debug key, as per the config in /android/app/build.gradle -> buildTypes -> signingConfig this may impact your correct hash
Google signs the app with another key when we upload it to the Play Store
We sign the app with our key to upload the AAB or APK, but it signs the app with an internally controlled key. Remember this to generate the hash!
If your app is published on the Play Store with keys being managed by Google, you must do the following:
On the Google Play Console page when we select our app after logging in, on the left side of the page we have the "Versions" category
Let's look at Versions -> Settings -> App Health
There we have the two credentials of our app (upload and deploy), let's download the deploy certificate
Now we need to generate the keystore from this certificate, for that we run the command:
keytool -importcert -file deployment_cert.der -keystore ps-deploy.keystore -alias myalias
Enter a storage password when prompted
Now that we have the correct .keystore file, we continue with the process of generating the hash.
./key2.sh ./ps-deploy.keystore myalias br.com.example.app
Remember that the emulator has a function that allows us to send sms and is very useful for testing this lib
Body of the SMS I used
<#>test body, codigo de verificacao: 0614
Sorry for translation errors, if you have something to add or contribute, please put it here. we are all learning