A Step-by-Step Guide For Generating Google & Facebook Key Hash For Android Apps

Sanjay Mahapatra Published on : 17 December 2024 8 minutes

Learn how to seamlessly integrate third-party social apps with your video/audio streaming app by generating key hash. This blog exclusively covers the key hash generation of Google and Facebook Android apps. Continue reading

Key Hash For Google and Facebook

In the fast-paced world of streaming, ensuring seamless integration with popular Android apps like Google and Facebook is crucial for enhancing user experience and functionality. One key aspect of this integration is generating the Key Hash—a unique identifier that allows your Android app to communicate securely with platforms like Google and Facebook.

Whether you’re setting up social login, API connections, or other integrations, having the correct Key Hash is a fundamental step. For many developers, this process can seem technical and overwhelming. That’s why we’ve created this comprehensive guide to walk you through the step-by-step process of how to generate key Hash for Android apps.

In this blog, we’ll cover everything you need to know about generating Key Hashes for both Google and Facebook platforms, using tools like OpenSSL, JDK, and the Android Studio terminal. By the end of this guide, you’ll have a clear understanding of how to create these Key Hashes and seamlessly integrate them into your streaming app development workflow.

How To Generate Google Key Hash for Android Apps?

In this section, we will explore the steps to generate an SHA key for integrating Google Sign-In with your Android app. Google requires an SHA-1 key to verify your app’s identity for authentication services like Google Sign-In.

Prerequisites To Get Started

  1. Java Development Kit (JDK): Ensure the JDK is installed on your system. If not, you can download it from Oracle JDK.

  2. Android Studio: Ensure that Android Studio is installed and your Android project is set up.

Here’s the Step-by-Step Instructions For Generating Google Key Hash For Android Apps

1. Generating the SHA-1 Key for Debug Builds

For debug builds, Android Studio automatically creates a debug keystore, located in a specific directory. You can generate an SHA-1 key from this keystore using the following steps.

macOS/Linux

Open a Terminal and run the following command:

keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

Example: –

keytool -exportcert -alias androiddebugkey -keystore “C:\Users\Sanjay\.android\debug.keystore” | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” sha1 -binary | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” base64

  1. When prompted for the password, type: android
  2. The output will show various details about the key. Look for the line labeled SHA1, which looks like this:
    SHA1: AB:CD:EF:12:34:56:78:90:AB:CD:EF:12:34:56:78:90:12:34:56:78
  3. This is your Google Sign-In SHA-1 key.

Windows

Open the Command Prompt and navigate to your JDK’s bin directory:
cd “C:\Program Files\Java\jdk<version>\bin”

  1. Run the following command:
    keytool -list -v -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore
  2. When prompted for the keystore password, type: android
  3. Look for the line labeled SHA1 in the output. This is your SHA-1 key.

2. Generating the SHA-1 Key for Release Builds

For release builds, you must use your own release keystore. Follow these steps to generate the SHA-1 key for release builds.

  1. Navigate to the directory where your release keystore is stored. If you haven’t created one yet, follow this guide to create a release keystore.

Open a Terminal (macOS/Linux) or Command Prompt (Windows) and run the following command:

keytool -list -v -alias <your-key-alias> -keystore <path-to-your-release-keystore>

Example: –

C:\Users\Sanjay>keytool -exportcert -alias muvi -keystore “D:\androidprojects\muvi6_vod_android\app\src\sapphire\MuviReleaseCertificate.jks” -alias “muvi” | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” sha1 -binary | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” base64

  1. Replace <your-key-alias> with the alias of your key and <path-to-your-release-keystore> with the location of your release keystore file.

  2. When prompted for the keystore password, enter the password you set when you created the release keystore.

  3. Look for the SHA1 line in the output. This is your SHA-1 key.

3. Adding the SHA-1 Key to Your Google Developer Console

  1. Visit the Google Cloud Console.
  2. Log into your Google account.
  3. Select your project or create a new project.
  4. Navigate to APIs & Services > Credentials.
  5. Under OAuth 2.0 Client IDs, select the app for which you want to configure Google Sign-In.
  6. In the Authorized Certificates section, click Add SHA-1 Fingerprint.
  7. Paste the SHA-1 key you generated earlier and click Save.

4. Verifying the SHA-1 Key

After adding the SHA-1 key to the Google Developer Console, your Android app will be able to authenticate users using Google Sign-In.

Troubleshooting

  • Invalid password: For the debug keystore, ensure you’re using the default password android. For the release keystore, use the password you set when creating the keystore.
  • Missing OpenSSL: Ensure that the keytool command is in your system’s PATH, or use the full path to the keytool in your JDK’s bin directory.


By following these steps, you can successfully generate Google key hash for Android apps, enabling your users to seamlessly sign up/log into your streaming app with their respective Google accounts.

How To Generate Facebook Key Hash for Android Apps

This guide will help you generate Facebook key hash for Android apps. Key hashes are used by Facebook to verify the identity of the app. This process requires the keytool from the Java Development Kit (JDK) and OpenSSL.

Prerequisites

  1. Java Development Kit (JDK): Ensure that the JDK is installed. You can download it from Oracle JDK.

  2. OpenSSL: OpenSSL is required to generate the hash. You can download it from OpenSSL for Windows or OpenSSL for macOS.

  3. Extract the downloaded zip inside the C directory

  4. Open the extracted folder up to bin and copy the path, it should be something like C:\openssl-0.9.8k_X64\bin\openssl (add \openssl at end)

  5. So final JDK Location will be like C:\Program Files\Android\Android Studio\jre\bin

Here are the step-by-step instructions for generating Facebook Key Hash for Android Apps.

1. Generating the Key Hash on macOS/Linux

Open the Terminal on your macOS or Linux machine.

Debug Key Hash:    keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

 

Release Key Hash:   keytool -exportcert -alias your_alias -keystore path/to/your/release.keystore | openssl sha1 -binary | openssl base64

When prompted, enter the password.

The default password for the debug keystore is: android

2. Generating the Key Hash on Windows

For debug key hash

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Example:- 

“C:\Users\Sanjay\.android\debug.keystore” | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” sha1 -binary | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” base64

 

For release key hash

keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64

Example – 

C:\Users\Sanjay>keytool -exportcert -alias muvi -keystore “D:\androidprojects\muvi6_vod_android\app\src\sapphire\MuviReleaseCertificate.jks” -alias “muvi” | “C:\Users\Sanjay\Downloads\openssl-0.9.8k_X64\bin\openssl” sha1 -binary | “C:\Users\Mukesh\Downloads\openssl-0.9.8k_X64\bin\openssl” base64

Enter keystore password:  android

Our default key hash is – ga0RGNYHvNM5d0SLGQfpQWAPGJ8=

3. Adding the Key Hash to Your Facebook Developer Profile

  1. Visit the Facebook Developer Dashboard.
  2. Log into your Facebook account.
  3. Click on the top-right dropdown menu and select Developer Settings.
  4. In the left sidebar, select Your Apps.
  5. Select the app you’re working with or create a new app.
  6. Scroll down to Key Hashes and click Add.
  7. Paste the generated key hash from the previous step and click Save.

4. Verifying the Key Hash

After adding the key hash, your Android app will be able to communicate with Facebook services such as Facebook Login and other SDK features.

Troubleshooting

  • Incorrect password: Ensure you are using the default password android for the debug keystore. For release keystores, use the password you set.
  • Invalid command: Make sure you have the correct paths for keytool and openssl. If openssl is not installed or is not recognized, download and install it from the official website.


By following these steps, you can easily generate Facebook key hash for Android app’s Facebook integration. Repeat these steps for each development environment if needed.

Wrapping up

Generating Key Hash for Android apps is essential to integrate Google and Facebook platforms in your streaming app. By following the steps outlined in this guide, you can streamline the integration process and enhance your app’s performance.

At Muvi, we simplify the technical challenges of app development, offering end-to-end solutions for building and managing feature-rich applications. Whether it’s social integrations, API management, or scaling your app’s capabilities, Muvi has you covered. Ready to take your app to the next level? Get in touch with us today!

Written by: Sanjay Mahapatra

A dedicated Android developer at Muvi, Sanjay is passionate about exploring new technologies and crafting user-friendly mobile applications. Known for meeting deadlines and blending creativity with precision, Sanjay strives to enhance user experiences. 'Innovate, Collaborate, and Elevate’ is his mantra.

Add your comment

Leave a Reply

Your email address will not be published.

Try Muvi One Free
For 14 Days

No Credit Card Required

Free Trial