CodeSign Secure Documentation
  • Overview
    • About CodeSign Secure
    • Getting Started
    • Documentation Guide
    • Portal Overview
    • Troubleshooting
      • FAQ
    • Glossary
  • Reference Guide
    • Header Bar
      • CodeSign Secure Documentation
      • Swagger API
      • Profile Section
    • Dashboard
      • Key Performance Indicators
      • Issued Certificates
      • Signatures Generated
      • HSM Health Check
    • Keys and Certificates
      • Key and Certificate Lifecycle
    • App Management
    • Signing Requests
      • Approval Workflows
    • Signing Tools
    • Reports
      • Signing Request Report
      • Audit Trail
      • Certificate Report
      • Client Report
    • Logs
    • System Setup
      • Identity Store
      • Backup
      • User
      • Roles and Permissions
      • Email
      • Signing Projects
      • SSL/TLS Management
      • Environment
      • Plugins
  • Setup & Architecture
    • Identity and Access Control
    • Architecture and Concepts
    • Installation
      • Windows
        • Installing the Server
        • Ports and Protocols
        • High Availability and Backup
        • Upgrades and Compatibility
    • Security
      • Security Hardening Checklist
      • Client Authentication
      • Designing Signing Policies
  • Release Notes
    • Releases for 2026
      • v3.2.1
    • Releases for 2025
      • v3.2.0
    • Releases for 2024
      • v3.1.0
  • API Reference
    • Getting Started
    • Authorizing Requests
    • Securing API Access
    • Request and Response Conventions
    • Endpoint Reference
      • Signing
      • Signing Requests
      • Certificates
      • Applications and Environments
      • User Management
      • Permissions
      • Email
      • System Setup
      • Reports
      • Dashboard
      • License
  • Integration Guides
    • Signing Capabilities
      • Supported Formats and Platforms
      • Timestamping
      • Windows Signing - SignTool
        • Signing
        • Macro Signing
      • Apple Signing
      • AppX & MSIX Signing
      • Visual Studio ClickOnce
      • Jar Signing
      • Sign HLK/HCK using CodeSign Secure
      • NuGet Signing
      • Mage Signing
      • Sign OVA/OVF using Encryption Consulting’s Utility Tool
      • Utility Tool for code signing
      • Container Signing
      • PKCS11 Wrapper
        • APK Signing
        • OpenSSL Signing
        • XML Signing
        • JSign Tool Signing
        • Jarsigner Signing
        • GPG2, Debian & RPM Signing
      • Reproducible Build
        • Automated Hash Validation
        • Reproducible Build Process Flow
        • Pipeline Script Components
        • Hash Validation
    • CI/CD Integration
      • GitHub Actions
      • Jenkins
      • GitLab
      • Azure DevOps
      • TeamCity
      • Bamboo
      • Securing CI/CD Credentials

APK Signing

For APK signing, we use APKSigner which is command-line utility included in the Android SDK Build Tools that allows you to sign Android application package (APK) files and verify their signatures. It's an essential tool for Android developers to ensure the integrity and authenticity of their apps.

For Linux - Ubuntu

To sign your APK using APKSigner and our PKCS#11 wrapper in Ubuntu, please follow the below steps:

  • Go to EC CodeSign Secure’s v3.02’s Signing Tools section and download the PKCS11 Wrapper for Ubuntu.

    PKCS11 Wrapper Linux

  • After that, generate a P12 Authentication certificate from the System Setup > User > Generate Authentication Certificate dropdown.

    Authentication Certificate

  • Go to your Ubuntu client system and edit the configuration files (ec_pkcs11client.ini and pkcs11properties.cfg) downloaded in the PKCS11 Wrapper.

    APK configuration setup Linux

    NOTE: When using Luna HSM, add the slot number in the pkcs11properties.cfg file as shown below:

    APK configuration setup Linux in Luna

  • Now we need to add the environment variable for the pkcs11 client library.

    Run the below command to open the bashrc file:

    nano ~/.bashrc

    Open Nano File

    Now add the EC_INI_FILE_PATH variable with the path of the .ini at the end of the bashrc file, like:

    export EC_INI_FILE_PATH=/home/administrator/PKCS11_Wrapper-Ubuntu/ec_pkcs11client.ini

    Set Variable

    Press Ctrl+X, then enter Y, and then press Enter to save.

    Reload the environment variables

    source ~/.bashrc

    Reload Nano File

    Check whether the variable has been set correctly

    echo $EC_INI_FILE_PATH

    Check Variable

    NOTE: If you can't see the file location from echo commands, open a new terminal and try again.

  • Now, let’s install some prerequisites in your client system to run the PKCS11 Wrapper.

    • Install Java 8: sudo apt install openjdk-8-jdk

      JDK 8 installation on Linux

    • Set Java 8 as the active version: sudo update-alternatives --config java

      Set JDK 8 path on Linux

    • Install the Android SDK command-line tools: sudo apt install google-android-cmdline-tools-13.0-installer

      Android JDK installation on Linux

    • Ensure that the SDK Manager for Android Studio has been properly installed: sdkmanager --version

      Verify Android JDK on Linux

    • Install Build tools using SDKManager, which contains the APKSigner: sdkmanager "build-tools;34.0.0"

      Install SDKManager on Linux

    • Ensure that APKSigner is present: apksigner --version

      Verify apksigner on Linux

    • Two packages are required to run the PKCS11 Wrapper on your system. First, install liblog4cxx-dev using: sudo apt-get install liblog4cxx-dev

      Install libblog4 library on Linux

    • The last prerequisite is to install the curl package: sudo apt-get install curl

      Install curl library on Linux

  • Signing

    Now that all the configurations and prerequisites have been installed. Let’s perform the signing operation first.

    The signing command will look something like this (ensure you run this command only inside the folder where your PKCS11 Wrapper is installed):

    apksigner sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg <path of the pkcs11properties.cfg file in your system> --ks NONE --ks-type PKCS11 --ks-pass pass:abcd1234 --ks-key-alias <private key alias> --in <path of the APK file you want to sign> --out <path of the Signed APK file>

    A sample command is provided below:

    apksigner sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg /home/administrator/PKCS11_Wrapper-Ubuntu/pkcs11properties.cfg --ks NONE --ks-type PKCS11 --ks-pass env:KS_PASS --ks-key-alias EC-Cert-020 --in Sample.apk --out signed.apk

    Important: apksigner needs a keystore password argument. Put it in an environment variable, for example export KS_PASS='<password>' on Linux and macOS or set KS_PASS=<password> on Windows, instead of typing it on the command line, where it is saved in shell history and CI logs. Replace EC-Cert-020 with the key label of your signing certificate.

    APK Signing on Linux

    NOTE: When working with Luna HSM, use the following signing command structure:

    apksigner sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg <path of the pkcs11properties.cfg file in your system> --ks NONE --ks-type PKCS11 --ks-pass pass:abcd1234 --ks-key-alias <private key alias> --in <path of the APK file you want to sign> --out <path of the Signed APK file> --min-sdk-version 28

    Verification

    After successfully signing the APK, let’s verify it using this command:

    apksigner verify -verbose <path of the signed APK file>

    A sample command is provided below:

    apksigner verify -verbose signed.apk

    APK Verifying on Linux

    NOTE: When working with Luna HSM, use the following verifying command structure:

    apksigner verify -verbose --min-sdk-version 28 <path of the signed APK file>
For MacOS

To perform APK Signing using APKSigner Tool and our PKCS11 Wrapper in MacOS machine, you would need to follow the below steps:

  • Go to EC CodeSign Secure’s v3.02’s Signing Tools section and download the PKCS11 Wrapper for MacOS.

    PKCS Wrapper for MacOS

  • After that, generate a P12 Authentication certificate from the System Setup > User > Generate Authentication Certificate dropdown.

    Authentication Certificate

  • Go to your MacOS client system and edit the configuration files (ec_pkcs11client.ini and pkcs11properties.cfg) downloaded in the PKCS11 Wrapper.

    APK configuration setup MacOS

    NOTE: When using Luna HSM, add the slot number in the pkcs11properties.cfg file as shown below:

    Configuration setup in MacOS

  • Now, let’s install some prerequisites in your client system to run the PKCS11 Wrapper.

    • Install Java 17: brew install openjdk@17

      JDK 17 installation on Mac

    • Set Java 17 as the active version

      For Zsh: nano ~/.zshrc

      JDK 17 setup in Zsh on Mac

      For Bash: nano ~/.bash_profile

      JDK 17 setup in Zsh on Mac

      Add these lines:
      export JAVA_HOME=$(/usr/libexec/java_home -v 17)
      export PATH=$JAVA_HOME/bin:$PATH

      And then run:
      source ~/.zshrc
      or
      source ~/.bash_profile

    • Install the Android SDK command-line tools from this site

      APKSigner installation on Mac
      APKSigner installation on Mac

    • Ensure that the SDK Manager for Android Studio has been properly installed: sdkmanager --sdk_root=/Users/subhayuroy/PKCS11_Wrapper-Mac --version

      SDKManager verification on Mac

    • Install Build tools using SDKManager, which contains the APKSigner: sdkmanager --sdk_root=/Users/subhayuroy/PKCS11_Wrapper-Mac "build-tools;34.0.0"

      Install Build Tools on Mac

    • Ensure that APKSigner is present: ls /Users/subhayuroy/PKCS11_Wrapper-Mac/build-tools/34.0.0/apksigner

      Apksigner verify on Mac

    • Two packages are required to run the PKCS11 Wrapper on your system. First, install liblog4cxx-dev using: brew install log4cxx

      Install log4cxx library on Mac

    • The last prerequisite is to install the curl package: brew install curl

      Install curl library on Mac

    • You need to ensure all the relative paths are added to your PATH variable (~/.zshrc file):
      export PATH=/Users/subhayuroy/PKCS11_Wrapper-Mac/cmdline-tools/bin:$PATH
      export JAVA_HOME=$(/usr/libexec/java_home -v 17)
      export PATH=$JAVA_HOME/bin:$PATH
      export ANDROID_SDK_ROOT=/Users/subhayuroy/PKCS11_Wrapper-Mac
      export PATH=$PATH:/Users/subhayuroy/PKCS11_Wrapper-Mac/build-tools/34.0.0

      Verify library paths on Mac

  • Signing

    Now that all the configurations and prerequisites have been installed. Let’s perform the signing operation first.

    The signing command will look something like this (ensure you run this command only inside the folder where your PKCS11 Wrapper is installed):

    java --add-exports=jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED -jar <path of the apksigner.jar in your system> sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg <path of the pkcs11properties.cfg file in your system> --ks NONE --ks-type PKCS11 --ks-pass env:KS_PASS --ks-key-alias <private key alias> --in <path of the APK file you want to sign> --out <path of the Signed APK file>

    A sample command is provided below:

    java --add-exports=jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED -jar /Users/subhayuroy/PKCS11_Wrapper-Mac/build-tools/34.0.0/lib/apksigner.jar sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg /Users/subhayuroy/PKCS11_Wrapper-Mac/pkcs11properties.cfg --ks NONE --ks-type PKCS11 --ks-pass env:KS_PASS --ks-key-alias EC-Cert-020 --in Sample.apk --out signed.apk

    APK Signing on Mac

    Verification

    After successfully signing the APK, let’s verify it using this command:

    apksigner verify -verbose <path of the signed APK file>

    A sample command is provided below:

    apksigner verify -verbose signed.apk

    APK Verifying on Mac

For Windows

To perform APK Signing using APKSigner Tool and our PKCS11 Wrapper in Windows machine, you would need to follow the below steps:

  • Go to EC CodeSign Secure’s v3.02’s Signing Tools section and download the PKCS11 Wrapper for Windows.

    PKCS Wrapper Windows

  • After that, generate a P12 Authentication certificate from the System Setup > User > Generate Authentication Certificate dropdown.

    Authentication Certificate

  • Go to your Windows client system and edit the configuration files (ec_pkcs11client.ini and pkcs11properties.cfg) downloaded in the PKCS11 Wrapper.

    APK configuration setup Windows
    APK configuration setup Windows
    APK configuration setup Windows

    NOTE: When using Luna HSM, add the slot number in the pkcs11properties.cfg file as shown below:

    Configuration setup in Luna

  • Now, let’s install some prerequisites in your client system to run the PKCS11 Wrapper.

    • Install Java 22 from Oracle’s official site, and follow the instructions in the msi file.

      Install JDK 22 on Windows
      Install JDK 22 on Windows
      Install JDK 22 on Windows

    • Set Java 22 as the active version by storing the bin path in the PATH variable.

      APK Set JDK 22 on Windows

    • Install the Android SDK command-line tools from this link here.

      APKSigner installation on Windows

    • Extract the files into a “cmdline-tools” folder and create a subfolder named latest. Now, move the bin and lib folders into the latest folder.

      APKSigner setup on Windows

    • Set an environment variable called ANDROID_HOME and set it to the path where you extracted the command line tools.

      APKSigner environment variables on Windows

    • Install Build tools using SDKManager, which contains the APKSigner: .\bin\sdkmanager --channel=0 --install "build-tools;34.0.0"

      Install build tools on Windows

    • Ensure that APKSigner is present: Apksigner.bat --version

      Verify APKSigner on Windows

    • Open the Apksigner.bat file and update the last line to the below command:

      Original APKSigner.bat on Windows

      call "%java_exe%" --add-exports jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED %javaOpts% -jar "%jarpath%" %params%

      Update APKSigner.bat on Windows

  • Signing

    Now that all the configurations and prerequisites have been installed. Let’s perform the signing operation first.

    The signing command will look something like this (ensure you run this command only inside the folder where your PKCS11 Wrapper installed):

    apksigner sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg <path of the pkcs11properties.cfg file in your system> --ks NONE --ks-type PKCS11 --ks-pass env:KS_PASS --ks-key-alias <private key alias> --in <path of the APK file you want to sign> --out <path of the Signed APK file>

    A sample command is provided below:

    apksigner sign --provider-class sun.security.pkcs11.SunPKCS11 --provider-arg C:\Users\riley\Downloads\PKCS11_Wrapper-Windows\pkcs11properties.cfg --ks NONE --ks-type PKCS11 --ks-pass env:KS_PASS --ks-key-alias EC-Cert-020 --in Sample.apk --out signed.apk

    APK Signing on Windows

    Verification

    After successfully signing the APK, let’s verify it using this command:

    apksigner verify -verbose <path of the signed APK file>

    A sample command is provided below:

    apksigner verify -verbose signed.apk

    APK Verifying on Windows

On this Page:
Support Privacy Policy Terms of Service

Copyright Encryption Consulting LLC. All rights reserved.