DEV Community

sunny prasad
sunny prasad

Posted on • Updated on

Find SHA1 keys quickly from jks and apk

xubuntu

Specs are

  • xubuntu 19.04
  • fresh android studio
  • fresh flutter installation

For this command to run we need keytool.

All the guides on the internet will ask you to go to jdk/bin.
However, Now android studio includes jdk as part of the installation.

So we can edit our .zshrc file and add JDK etc to the path.

Mine has platform tools, tools,flutter and studio's jdk added.

open zshrc
nano .zshrc

Paste these and change those paths as per your installation

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/home/prasadsunny1/.oh-my-zsh"
export ANDROID_HOME="/home/prasadsunny1/Documents/sdks/android"
export PATH="/home/prasadsunny1/Documents/sdks/flutter/bin":$PATH
export PATH="/home/prasadsunny1/Documents/android-studio/jre/bin":$PATH

path=("${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools" $path)

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"


run this command
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

you should get an output like this

➜  ~ keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
Alias name: androiddebugkey
Creation date: 10 Dec, 2019
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: C=US, O=Android, CN=Android Debug
Issuer: C=US, O=Android, CN=Android Debug
Serial number: 1
Valid from: Tue Dec 10 23:52:27 IST 2019 until: Thu Dec 02 23:52:27 IST 2049
Certificate fingerprints:
     MD5:  xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
     SHA1: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
     SHA256: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
Signature algorithm name: SHA1withRSA
Subject Public Key Algorithm: 2048-bit RSA key
Version: 1

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /home/prasadsunny1/.android/debug.keystore -destkeystore /home/prasadsunny1/.android/debug.keystore -deststoretype pkcs12".

Here in the middle, you have your SHA1 key.

Find SHA1 from your apk

  • extract apk and get META_INF/**.RSA
  • find keytool inside androidstudio installation and open powershell there
  • run keytool -printcert -file name.RSA

That's all, Thaks for reading

Follow me on twitter http://twitter.com/prasadsunny1

Top comments (0)