Skip to content

Instantly share code, notes, and snippets.

@berkedel
Created October 12, 2020 10:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save berkedel/a37abd1487b2db54079b20bc4d8befca to your computer and use it in GitHub Desktop.
Save berkedel/a37abd1487b2db54079b20bc4d8befca to your computer and use it in GitHub Desktop.
How to import x509.pem pk8 file into jks keystore

How to import x509.pem pk8 file into jks keystore

Prerequiste:

Generate a file platform.priv.pem from you pk8 file.

openssl pkcs8 -in platform.pk8 -inform DER -outform PEM -out platform.priv.pem -nocrypt

Generate platform.pk12 file using both your platform.x509.pem file and the previously generated platform.priv.pem. The key alias KEY_ALIAS is a string value and it can be anything. After entering command below, you'll be prompted for a password (and a password confirmation). It will be your a key password KEY_PASSWORD.

openssl pkcs12 -export -in platform.x509.pem -inkey platform.priv.pem -out platform.pk12 -name {{KEY_ALIAS}}

Create a brand new jks file STORE_FILE_NAME, and import your key with the given key alias and password before. Once the command below is entered, you'll be prompted for the store password STORE_PASSWORD.

keytool -importkeystore -destkeystore {{STORE_FILE_NAME}}.jks -srckeystore platform.pk12 -srcstoretype PKCS12 -srcstorepass {{KEY_PASSWORD}} -alias {{KEY_ALIAS}}

You already defined:

  1. key alias
  2. key password
  3. store password
  4. store file name

Finally update your signing config on app's build.gradle.

android {
    signingConfigs {
        release {
            storeFile file('/replace/with/path/to/your/{{STORE_FILE_NAME}}.jks')
            storePassword '{{STORE_PASSWORD}}'
            keyAlias = '{{KEY_ALIAS}}'
            keyPassword '{{KEY_PASSWORD}}'
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment