Get certificate fingerprint from android app
I put it here - the function gives the same result as keytool does it.
private String getCertificateSHA1Fingerprint() {
PackageManager pm = mContext.getPackageManager();
String packageName = mContext.getPackageName();
int flags = PackageManager.GET_SIGNATURES;
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(packageName, flags);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Signature[] signatures = packageInfo.signatures;
byte[] cert = signatures[0].toByteArray();
InputStream input = new ByteArrayInputStream(cert);
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X509");
} catch (CertificateException e) {
e.printStackTrace();
}
X509Certificate c = null;
try {
c = (X509Certificate) cf.generateCertificate(input);
} catch (CertificateException e) {
e.printStackTrace();
}
String hexString = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] publicKey = md.digest(c.getEncoded());
hexString = byte2HexFormatted(publicKey);
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (CertificateEncodingException e) {
e.printStackTrace();
}
return hexString;
}
public static String byte2HexFormatted(byte[] arr) {
StringBuilder str = new StringBuilder(arr.length * 2);
for (int i = 0; i < arr.length; i++) {
String h = Integer.toHexString(arr[i]);
int l = h.length();
if (l == 1) h = "0" + h;
if (l > 2) h = h.substring(l - 2, l);
str.append(h.toUpperCase());
if (i < (arr.length - 1)) str.append(':');
}
return str.toString();
}
How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?
Easiest ways ever:
Update added for Android Studio V 2.2 in last step
There are two ways to do this.
1. Faster way:
- Open Android Studio
- Open your Project
- Click on Gradle (From Right Side Panel, you will see Gradle Bar)
- Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of your Project)
- Click on Your Project (Your Project Name form List (root))
- Click on Tasks
- Click on Android
- Double Click on signingReport (You will get SHA1 and MD5 in Run Bar(Sometimes it will be in Gradle Console))
- Select app module from module selection dropdown to run or debug your application
Check the screenshot below:
2. Work with Google Maps Activity:
- Open Android Studio
- Open Your Project
- Click on File menu -> Select New -> Click on Google -> Select Google Maps Activity
- A dialog would appear -> Click on Finish
- Android Studio would automatically generate an XML file named with
google_maps_api.xml
- You would get debug SHA1 key here (at line number 10 of the XML file)
Check Screenshot below:
Android Studio V 2.2 Update
There is an issue with Execution.
Solution:
- Click on Toggle tasks execution/text mode from Run bar
Check Screenshot below:
Done.
SHA-1 fingerprint of keystore certificate
Follow this tutorial for creating SHA1 fingerprint for Google Map v2
For Debug mode:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
for Release mode:
keytool -list -v -keystore {keystore_name} -alias {alias_name}
example:
keytool -list -v -keystore C:\Users\MG\Desktop\test.jks -alias test
On windows, when keytool command is not found, Go to your installed JDK Directory e.g.
<YourJDKPath>\Java\jdk1.8.0_231\bin\
, open command line and try the above commands for debug/release mode.
Another way of getting your SHA1 OR SHA-256 use ./gradlew signingReport
For more detailed info visit
Using Gradle's Signing Report
How to obtain Signing certificate fingerprint (SHA1) for OAuth 2.0 on Android?
Start an export process to create an apk for your app and use your production key. The very last page displays both your SHA1 and MD5 certificate fingerprints
get android release Certificate Fingerprints
Just to test it (with the debug fingerprint), run the following command in any directory with the terminal.
$ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v
Then copy the SHA1 value and paste it into your Firebase console.
Be careful, the above will work for the debug environment, if you want to set up the release fingerprint you will have to create a keystore, check out this post to see how to do it, and then run the same command but instead of ~/.android/debug.keystore
you should put ~/YOUR/PATH/TO/KEYSTORE
$ keytool -exportcert -alias androiddebugkey -keystore ~/YOUR/PATH/TO/KEYSTORE -list -v
Android: What is a keystore file, and what is it used for?
Android - Release certificate fingerprint different between keytool and final Play Store bundle
When you created your first release, you were prompted whether you wanted to enroll in Play Signing and whether you wanted Play to create and store your app signing key. It seems that you have accepted. This means that Play will sign the APKs with the key they have created for you. You can read more about Play Signing here: https://support.google.com/googleplay/android-developer/answer/9842756
The key (and certificate) remain the same for the life of your app (unless you do some advanced operation like rotating app signing key), so the SHA-1 is not going to change and will always remain the same.
Note that if you create a new app, the SHA-1 is available in the App Signing page as soon as you enroll in Play Signing.
Get SHA1 fingerprint certificate in Android Studio for Google Maps
I got my Answer, it was quit simple.
Open Terminal,
Type command:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
Press Enter: You will get the following info, and SHA1 can be seen there.
.....
Certificate fingerprints:
MD5: 79:F5:59:................FE:09:D1:EC
SHA1: 33:57:0A:C9:..................:91:47:14:CD
SHA256: 39:AA:23:88:D6:...................33:DF:61:24:CB:17:47:EA:39:94:99
.......
Related Topics
Android - Get Time of Chronometer Widget
Android Material: Status Bar Color Won't Change
How to Draw a Route, Along an Existing Road, Between Two Points
Android Speech Recognition Continuous Service
How to Resolve "Waiting for Debugger" Message
How to Set Android_Sdk_Home Environment Variable
Error :: Duplicate Files During Packaging of APK
Get Cursor Position in Android in Edit Text
How to Use View.Ontouchlistener Instead of Onclick
Android Type_Linear_Acceleration Sensor - What Does It Show
How to Set Text in an Edittext
Add Floating Point Value to Android Resources/Values
Fragment in Viewpager Using Fragmentpageradapter Is Blank the Second Time It Is Viewed
Controlling the Camera to Take Pictures in Portrait Doesn't Rotate the Final Images
How to Share a Single Library Source Across Multiple Projects
Permission Denial: Startforeground Requires Android.Permission.Foreground_Service