I need to get some hash from my app signing for Facebook SDK https://developers.facebook.com/quickstarts/?platform=android
We could get like this but old way because seems Facebook doesn't know that app now uses Google Play Signing and it's an upload keystore:
keytool -exportcert -alias MY_ALIAS_NAME -keystore MY_PATH_TO_KEYSTORE_FILE | openssl sha1 -binary | openssl base64
So I found this answer https://stackoverflow.com/a/54682874/7767664 which suggests to use SHA1 and convert with http://tomeko.net/online_tools/hex_to_base64.php
But I tested this solution with SHA1 of my upload key and that converter website and solution from Facebook keytool -exportcert -alias UPLOAD_KEY_ALIAS_NAME -keystore PATH_TO_UPLOAD_KEYSTORE_FILE | openssl sha1 -binary | openssl base64
and results are different! It's not the same at all
What does it mean? Why results are different?
So I can copy SHA1 from Google Play Console website for needed app but I can't use http://tomeko.net/online_tools/hex_to_base64.php because it doesn't work the same as using keystore and openssl commands
CodePudding user response:
I had the same problem as yours years ago, so I wrote a separate .java tool to generate Facebook SDK base64 string by providing SHA1.
I don't remember what I've tried at that time. Here is what I've done:
1/ Create file: SHA1ToBase64Converter.java
import java.util.Base64;
import java.lang.IllegalArgumentException;
public final class SHA1ToBase64Converter {
public static void main(String[] args) {
System.out.println("--------------------------------------------");
if (args == null || args.length < 1) {
System.out.println("Convert failed");
throw new IllegalArgumentException("No SHA1 string is provided in the parameter");
}
String[] sha1Components = args[0].split(":");
byte[] sha1 = new byte[sha1Components.length];
for (int i = 0; i < sha1.length; i) {
sha1[i] = (byte) (Integer.parseInt(sha1Components[i], 16) & 0xff);
}
System.out.println("Convert successful");
System.out.println("Base64 string: " Base64.getEncoder().encodeToString(sha1));
}
}
Run above file using installed javac:
javac SHA1ToBase64Converter.java
java SHA1ToBase64Converter {{ SHA1 copied from PlayStore }}
2/ Or another option is to run your project and make it run the code for you:
// This same code can be used in an Android project if you haven't installed javac or java command line
// Place this somewhere in your code and wait for the Log result
String[] sha1Components = YOUR_SHA1_STRING.split(":");
byte[] sha1 = new byte[sha1Components.length];
for (int i = 0; i < sha1.length; i) {
sha1[i] = (byte) (Integer.parseInt(sha1Components[i], 16) & 0xff);
}
Log.d("FBBase64KeyTag", Base64.encodeToString(sha1, Base64.NO_WRAP));
CodePudding user response:
It seems facebook docs are totally wrong because when using keytool -exportcert -alias MY_ALIAS_NAME -keystore MY_PATH_TO_KEYSTORE_FILE | openssl sha1 -binary | openssl base64
command on Windows 10 it will generate base64 string of 32 size but facebook accepts hashes only of 28 size
Seems http://tomeko.net/online_tools/hex_to_base64.php is correct one and it generates base64 string of 28 size