APK Signing Method and System Based on Hardware Encryption Card

By generating a key pair in the hardware encryption card and switching the signing path, the problems of APK signing private key leakage and abnormal response of the hardware encryption card are solved, realizing a secure and stable APK signing process with good compatibility and low cost.

CN123116249APending Publication Date: 2026-11-17晨兴希姆通电子(桐城)有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611219082.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-12
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In the Android system, the APK signing private key is stored as a file in the compilation environment, which poses a risk of leakage. Furthermore, the hardware encryption card has issues with abnormal response during concurrent and continuous calls.

Method used

The system generates key pairs and exports certificates in the hardware encryption card, switches the signature path by detecting the signature mark on the hardware encryption card, performs signatures using the hardware encryption card, and ensures stability through concurrency control and preset waiting time. It communicates using a standardized HTTP interface and a PKCS#11 interface.

Benefits of technology

The signature private key is generated and stored in the hardware encryption card, avoiding the risk of leakage, compatible with the native signature method, reducing migration costs, improving the security and stability of the signature, and avoiding hardware access conflicts and abnormal responses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123116249A_ABST
    Figure CN123116249A_ABST
Patent Text Reader

Abstract

This invention relates to an APK signing method and system based on a hardware encryption card. The method includes: generating at least one key pair for APK signing in the hardware encryption card, and exporting an X.509 certificate corresponding to the key pair from the hardware encryption card; during Android compilation, determining the target private key for signing from the key pair according to the build configuration of the APK to be signed; detecting whether the hardware encryption card signing flag is enabled in the current compilation environment; when the hardware encryption card signing flag is enabled, switching the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path. The signing private key in this application is generated and stored in the hardware encryption card, and is not exposed in the compilation environment as a file, fundamentally avoiding the risk of private key leakage. Simultaneously, the signing path switching is achieved through the signing flag, enabling compatibility with both native signing and hardware signing methods.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and specifically to an APK signing method and system based on a hardware encryption card. Background Technology

[0002] In the Android system, APK files need to be signed and verified during installation, upgrades and system integration. The APK signature is used to prove the identity of the APK publisher and to ensure that the APK file has not been tampered with after signing. When installing or updating an application, the Android system will perform a signature consistency check based on the signature certificate carried in the APK. If the signatures do not match, the installation or update will be refused, thereby preventing malicious applications from disguising themselves as legitimate applications.

[0003] In the native Android build system, APK signing typically uses private keys and certificates stored locally. The Android source tree usually contains a `build / target / product / security / ` directory, which may include files such as `networkstack.pk8`, `networkstack.x509.pem`, `testkey.pk8`, `testkey.x509.pem`, `platform.pk8`, and `platform.x509.pem`. Among them, the file with the `.pk8` extension is the private key file, and the file with the `.x509.pem` extension is the certificate file. During the Android compilation process, different APKs select different signing keys for signing based on the certificate configuration items in their `Android.mk` or `Android.bp` files.

[0004] However, in the aforementioned native signature mechanisms, the signing private key is stored as a file in the compilation environment. If there are security flaws in the compilation server, source code repository, or permission management mechanism, the private key file may be copied, leaked, or misused. For system-level signature keys such as platform, media, shared, and networkstack, once leaked, attackers may use the leaked private key to sign malicious APKs, thereby bypassing system signature verification and causing serious information security risks.

[0005] While storing the signing private key in a hardware encryption card can prevent the private key from being exposed as a file, hardware encryption cards still have many problems when used in the Android build signing process. For example, the native Android signing tools are mainly designed for local private key files and certificate files and cannot directly call the hardware encryption card to complete the signing. The Android build process has strong concurrency characteristics, and multiple APKs may enter the signing stage at the same time, while hardware encryption cards usually do not support multi-threaded concurrent access. Some hardware encryption cards may experience abnormal device response when called continuously and quickly. Summary of the Invention

[0006] The purpose of this invention is to overcome the shortcomings of the prior art and provide an APK signing method and system based on a hardware encryption card, which solves the problem that the APK signing private key is stored in the compilation environment as a file in the prior art, which makes the private key easy to be leaked.

[0007] To achieve the above objectives, the present invention provides an APK signing method based on a hardware encryption card, comprising: Generate at least one key pair for APK signing in the hardware encryption card, and export the X.509 certificate corresponding to the key pair from the hardware encryption card; During the Android compilation process, the target private key for signing is determined from the key pair based on the build configuration of the APK to be signed; Check if hardware encryption card signature marking is enabled in the current compilation environment; When the hardware encryption card signature flag is detected to be enabled, the signing task of the APK to be signed is switched from the local private key file signing path to the hardware encryption card signing path. The hardware encryption card uses the target private key to perform a signing operation on the APK to be signed, generates a signed APK file, and writes the X.509 certificate corresponding to the target private key into the signed APK file.

[0008] By adopting this technical solution, the entire process of generating a key and exporting a certificate in a hardware encryption card, determining the target private key based on the build configuration, detecting the signature mark on the hardware encryption card, switching the signature path to the hardware encryption card, and having the hardware encryption card perform the signing and write the certificate to the APK is completed. The signing private key is generated and stored in the hardware encryption card and is not exposed in the compilation environment as a file, which fundamentally avoids the risk of private key leakage. At the same time, the signature path is switched through the signature mark, which can be compatible with native signing and hardware signing methods.

[0009] Furthermore, switching the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path includes: The native APK signing module sends the signing request of the APK to be signed to an independent hardware encryption signing service, which then calls the hardware encryption card to perform the signing.

[0010] By adopting this technical solution, the logic of signature calls is decoupled from the Android build system, reducing the intrusion into the build system.

[0011] Furthermore, the native APK signing module is the signapk module in the Android build system.

[0012] By adopting this technical solution, which involves modifying existing mature modules, the cost is low and the compatibility is good.

[0013] Furthermore, the hardware encryption signing service provides an HTTP interface, through which the native APK signing module submits signing requests to the hardware encryption signing service.

[0014] By adopting this technical solution and using a standardized HTTP interface for communication, it has good versatility and is easy for different signature clients to access.

[0015] Furthermore, the signature request includes at least one of the following: the path to the APK file to be signed, the output path of the signed APK, the alias of the target signature key, the path of the target signature certificate, the signature algorithm information, and the signature version information.

[0016] By adopting this technical solution, the data structure of the signature request is clearly defined, ensuring that all the information required for the signature task can be transmitted completely, thus guaranteeing the correct execution of the signature process.

[0017] Furthermore, the hardware encryption signature service is equipped with a concurrency control mechanism to limit multiple signature requests from accessing the hardware encryption card simultaneously. The concurrency control mechanism includes at least one of the following: mutex lock, task queue, single-threaded worker, distributed lock, and token scheduling mechanism.

[0018] By adopting this technical solution, the concurrency control mechanism can effectively avoid hardware access conflicts and signature failures caused by multiple signature requests accessing the site simultaneously, thus ensuring the stability of the signature process in concurrent compilation scenarios.

[0019] Furthermore, the hardware encryption signature service has a preset waiting time between two consecutive calls to the hardware encryption card to perform the signature operation, in order to avoid the hardware encryption card from malfunctioning due to rapid and continuous access.

[0020] By adopting this technical solution, the session abnormality problem caused by rapid and continuous access of the hardware encryption card can be avoided by setting a preset waiting time, thereby further improving the stability of the hardware signature process in concurrent compilation scenarios.

[0021] Furthermore, the hardware encryption signature service executes the signature by calling the private key in the hardware encryption card through the PKCS#11 interface.

[0022] By adopting this technical solution, the PKCS#11 interface has good versatility and can be compatible with various hardware encryption devices that support PKCS#11.

[0023] Furthermore, the hardware encryption signing service connects to the hardware encryption card through the SunPKCS11 provider and calls the apksigner tool to complete the APK signing.

[0024] By adopting this technical solution, no additional drivers are required, enabling simple and stable operation.

[0025] Furthermore, when calling the apksigner tool to complete APK signing, the parameters used include provider-class, provider-arg, ks-type, ks-key-alias, ks-pass, input APK path, and output APK path.

[0026] By adopting this technical solution, the specific parameter configuration for calling apksigner to perform hardware signing is clarified.

[0027] Furthermore, the hardware encryption card is a hardware security module or hardware encryption device that supports the PKCS#11 interface, including YubiKey and YubiHSM.

[0028] By adopting this technical solution, it is possible to cover mainstream hardware encryption devices, meaning it has good versatility.

[0029] Furthermore, the at least one key pair for APK signing includes at least one of networkstack, platform, media, shared, testkey, and releasekey.

[0030] By adopting this technical solution, the signing key types frequently used in the Android system are covered, enabling the solution to adapt to various system-level APK and application-level APK signing requirements.

[0031] Furthermore, the target private key for signing is determined from the key pair based on the build configuration of the APK to be signed, including: Read the Android.mk or Android.bp build file corresponding to the APK to be signed; When the build file contains LOCAL_CERTIFICATE or a corresponding certificate configuration item, the target private key is determined based on the certificate configuration item. If no certificate configuration item is configured in the build file, testkey or releasekey will be used as the target private key.

[0032] By adopting this technical solution, it is possible to be compatible with Android's native multi-certificate signing configuration mechanism, so that the APK's build configuration file can be adapted without modification.

[0033] Furthermore, the hardware encryption signing service is also used to accept secureboot firmware signing requests and call the hardware encryption card to complete the firmware signing.

[0034] By adopting this technical solution, APK signing and firmware signing use the same hardware access point, avoiding the concurrency conflict caused by different signing tools accessing the hardware separately, and realizing unified management of hardware resources.

[0035] Furthermore, when the native APK signing module determines that the current signing task is OTA package signing, it retains the original OTA package signing process and does not send the signing task to the hardware encryption signing service.

[0036] By adopting this technical solution, the impact on the OTA package signing process is avoided, ensuring the reliability of OTA package signing.

[0037] This invention also provides an APK signing system based on a hardware encryption card, characterized in that it includes: A hardware encryption card is used to generate and save APK signing key pairs and export the X.509 certificate corresponding to the APK signing key pairs; The build configuration parsing module is used to parse the build configuration of the APK to be signed during the Android build process and determine the target private key for signing from the key pair; The signature flag detection module is used to detect whether hardware encryption card signature flags are enabled in the current compilation environment; The signature path switching module is used to switch the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path when the hardware encryption card signing mark is enabled. The signature execution module is used to call the hardware encryption card to perform a signature operation on the APK to be signed using the target private key, generate a signed APK file, and write the X.509 certificate corresponding to the target private key into the signed APK file.

[0038] Furthermore, the signature path switching module includes: The native signature adaptation unit is used to send the signature request of the APK to be signed to an independent hardware cryptographic signature service; The hardware encryption signature service unit is used to receive the signature request and complete the signature by calling the target private key in the hardware encryption card through a concurrency control mechanism.

[0039] Furthermore, the hardware encryption signature service unit includes: The interface receiving subunit is used to receive signature requests; The task scheduling subunit is used to queue and schedule multiple signature requests; A hardware access control subunit is used to control access to the hardware encryption card via a mutex lock; The signature execution subunit is used to call an APK signing tool that supports PKCS#11 to complete the APK signing; The result output sub-unit is used to output the signed APK file.

[0040] Compared with the prior art, the present invention has the following advantages: 1. The signing private key is no longer stored in the compilation environment as a regular .pk8 file, but is generated and saved inside the hardware encryption card. The private key cannot be exported, which fundamentally avoids the risk of the private key file being copied or leaked, and improves the security of the APK signing key.

[0041] 2. By introducing a hardware encryption card signature marker into the Android build system, the build system can switch between the native signature process and the hardware encryption card signature process. It is compatible with both the traditional local private key file signing method and the hardware encryption card signing method, thus reducing the cost of migrating the solution.

[0042] 3. By sending the signing request to an independent hardware encryption signing service through the native APK signing module, the signing logic is decoupled from the Android build system, reducing the intrusion into the Android build system.

[0043] 4. The concurrency control mechanism effectively avoids hardware access conflicts and signature failures caused by multiple signature requests accessing the hardware encryption card simultaneously.

[0044] 5. The preset waiting time setting avoids abnormal device response caused by continuous calls to the hardware encryption card, and improves the stability of hardware encryption card signing in large-scale concurrent compilation scenarios.

[0045] 6. The hardware encryption signing service uniformly receives APK signing requests and secureboot firmware signing requests, enabling APK signing and firmware signing to use the same hardware access point. This avoids concurrency conflicts caused by different signing tools directly accessing the hardware encryption card, and achieves unified management of hardware encryption card access.

[0046] 7. Map the Android native certificate configuration items to the target private key in the hardware encryption card, so that the APK can automatically select the corresponding target private key for signing according to the build configuration, which is compatible with the Android native multi-certificate signing system and does not require modification of the APK build configuration file. Attached Figure Description

[0047] Figure 1 This is a flowchart illustrating the APK signing method based on a hardware encryption card according to the present invention. Figure 2 This is a schematic diagram of the APK signing process during the Android compilation process using the APK signing method based on a hardware encryption card according to the present invention; Figure 3 This is a schematic diagram of the hardware encryption signature service concurrency control process of the APK signing method based on a hardware encryption card according to the present invention; Figure 4 This is a schematic diagram of the signature path selection process for the signapk module in the APK signing method based on a hardware encryption card according to the present invention. Figure 5 This is a schematic diagram illustrating the process of unified access to the hardware encryption card for APK signing based on the hardware encryption card APK signing method of the present invention. Detailed Implementation

[0048] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.

[0049] Please see the appendix Figure 1-5This invention provides an APK signing method based on a hardware encryption card, comprising: generating at least one key pair for APK signing in the hardware encryption card, and exporting an X.509 certificate corresponding to the key pair from the hardware encryption card; during Android compilation, determining a target private key for signing from the key pair according to the build configuration of the APK to be signed; detecting whether the hardware encryption card signing flag is enabled in the current compilation environment; when the hardware encryption card signing flag is enabled, switching the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path; the hardware encryption card performing a signing operation on the APK to be signed using the target private key, generating a signed APK file, and writing the X.509 certificate corresponding to the target private key into the signed APK file; In the complete process of generating a key and exporting a certificate in a hardware encryption card, determining the target private key based on the build configuration, detecting the signature marker on the hardware encryption card, switching the signature path to the hardware encryption card, and having the hardware encryption card perform the signing and write the certificate to the APK, the signing private key is generated and stored in the hardware encryption card and is not exposed in the compilation environment as a file, which fundamentally avoids the risk of private key leakage. At the same time, the signature path is switched through the signature marker, which can be compatible with native signing and hardware signing methods.

[0050] Furthermore, switching the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path includes: the native APK signing module sends the signing request of the APK to be signed to an independent hardware encryption signing service, and the hardware encryption signing service calls the hardware encryption card to perform the signing; the signing call logic is decoupled from the Android build system, reducing the intrusion into the build system.

[0051] Furthermore, the native APK signing module is the signapk module in the Android build system; it is based on an existing mature module, which is low-cost and has good compatibility.

[0052] Furthermore, the hardware encryption signature service provides an HTTP interface, through which the native APK signing module submits signature requests to the hardware encryption signature service. The use of a standardized HTTP interface for communication provides good versatility and facilitates access for different signing clients.

[0053] The signature request includes at least one of the following: the path to the APK file to be signed, the output path of the signed APK, the alias of the target signature key, the path to the target signature certificate, the signature algorithm information, and the signature version information; the data structure of the signature request should be clearly defined to ensure that all the information required for the signature task can be transmitted completely, and to guarantee the correct execution of the signature process.

[0054] Furthermore, the hardware encryption signature service has an internal concurrency control mechanism to limit multiple signature requests from accessing the hardware encryption card simultaneously. The concurrency control mechanism includes at least one of the following: mutex lock, task queue, single-threaded worker, distributed lock, and token scheduling mechanism. The concurrency control mechanism can effectively avoid hardware access conflicts and signature failures caused by multiple signature requests accessing the card simultaneously, thus ensuring the stability of the signature process in concurrent compilation scenarios.

[0055] The hardware encryption signature service sets a preset waiting time between two consecutive calls to the hardware encryption card to perform the signature operation, in order to avoid the hardware encryption card from being abnormal due to rapid and continuous access. By setting the preset waiting time, session abnormality problems caused by rapid and continuous access of the hardware encryption card can be avoided, further improving the stability of the hardware signature process in concurrent compilation scenarios.

[0056] Furthermore, the hardware encryption signature service executes the signature by calling the private key in the hardware encryption card through the PKCS#11 interface; the PKCS#11 interface has good versatility and can be compatible with various hardware encryption devices that support PKCS#11.

[0057] The hardware encryption signing service connects to the hardware encryption card through the SunPKCS11 provider and calls the apksigner tool to complete APK signing; no additional drivers are required, achieving simple and stable operation.

[0058] When calling the apksigner tool to complete APK signing, the parameters used include provider-class, provider-arg, ks-type, ks-key-alias, ks-pass, input APK path, and output APK path; this clarifies the specific parameter configuration for calling apksigner for hardware signing.

[0059] The hardware encryption card is a hardware security module or hardware encryption device that supports the PKCS#11 interface, including YubiKey and YubiHSM; it can cover mainstream hardware encryption devices, that is, it has good versatility.

[0060] At least one key pair for APK signing includes at least one of networkstack, platform, media, shared, testkey, and releasekey; covering the signing key types commonly used in the Android system, enabling the solution to adapt to various system-level APK and application-level APK signing requirements.

[0061] Determining the target private key for signing from the key pair based on the build configuration of the APK to be signed includes: reading the Android.mk or Android.bp build file corresponding to the APK to be signed; if the build file has LOCAL_CERTIFICATE or the corresponding certificate configuration item, determining the target private key based on the certificate configuration item; if the build file does not have a certificate configuration item, determining testkey or releasekey as the target private key; it is compatible with Android's native multi-certificate signing configuration mechanism, so that the APK's build configuration file can be adapted accordingly without modification.

[0062] The hardware encryption signing service is also used to accept secureboot firmware signing requests and call the hardware encryption card to complete the firmware signing; this allows APK signing and firmware signing to use the same hardware access entry point, avoiding concurrency conflicts caused by different signing tools accessing the hardware separately, and realizing unified management of hardware resources.

[0063] When the native APK signing module determines that the current signing task is an OTA package signing task, it retains the original OTA package signing process and does not send the signing task to the hardware encryption signing service; this avoids affecting the OTA package signing process and ensures the reliability of OTA package signing.

[0064] This invention also provides an APK signing system based on a hardware encryption card, comprising: a hardware encryption card for generating and storing APK signing key pairs and exporting an X.509 certificate corresponding to the APK signing key pair; a compilation configuration parsing module for parsing the build configuration of the APK to be signed during Android compilation and determining the target private key for signing from the key pair; a signature mark detection module for detecting whether the hardware encryption card signature mark is enabled in the current compilation environment; a signature path switching module for switching the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path when the hardware encryption card signature mark is enabled; and a signature execution module for calling the hardware encryption card to perform a signing operation on the APK to be signed using the target private key, generating a signed APK file, and writing the X.509 certificate corresponding to the target private key into the signed APK file.

[0065] Furthermore, the signature path switching module includes: a native signature adaptation unit, used to send the signature request of the APK to be signed to an independent hardware encryption signature service; and a hardware encryption signature service unit, used to receive the signature request and complete the signature by calling the target private key in the hardware encryption card through a concurrency control mechanism.

[0066] Furthermore, the hardware encryption signature service unit includes: an interface receiving subunit for receiving signature requests; a task scheduling subunit for queuing and scheduling multiple signature requests; a hardware access control subunit for controlling access to the hardware encryption card through a mutex lock; a signature execution subunit for calling an APK signing tool that supports PKCS#11 to complete APK signing; and a result output subunit for outputting the signed APK file.

[0067] Based on the above methods and systems, the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein the processor executes the computer program to implement the above-described APK signing method based on a hardware encryption card.

[0068] Based on the above method and system, the present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described APK signing method based on a hardware encryption card.

[0069] The present invention has been described in detail above with reference to the accompanying drawings and embodiments. Those skilled in the art can make various modifications to the present invention based on the above description. Therefore, certain details in the embodiments should not be construed as limiting the present invention, and the scope of protection of the present invention shall be defined by the appended claims.

Claims

1. An APK signing method based on a hardware encryption card, characterized in that, include: Generate at least one key pair for APK signing in the hardware encryption card, and export the X.509 certificate corresponding to the key pair from the hardware encryption card; During the Android compilation process, the target private key for signing is determined from the key pair based on the build configuration of the APK to be signed; Check if hardware encryption card signature marking is enabled in the current compilation environment; When the hardware encryption card signature flag is detected to be enabled, the signing task of the APK to be signed is switched from the local private key file signing path to the hardware encryption card signing path. The hardware encryption card uses the target private key to perform a signing operation on the APK to be signed, generates a signed APK file, and writes the X.509 certificate corresponding to the target private key into the signed APK file.

2. The APK signing method based on a hardware encryption card according to claim 1, characterized in that, Switching the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path includes: The native APK signing module sends the signing request of the APK to be signed to an independent hardware encryption signing service, which then calls the hardware encryption card to perform the signing.

3. The APK signing method based on a hardware encryption card according to claim 2, characterized in that, The native APK signing module is the signapk module in the Android build system.

4. The APK signing method based on a hardware encryption card according to claim 2, characterized in that, The hardware encryption signing service provides an HTTP interface, through which the native APK signing module submits signing requests to the hardware encryption signing service.

5. The APK signing method based on a hardware encryption card according to claim 4, characterized in that, The signature request includes at least one of the following: the path to the APK file to be signed, the path to the APK output after signing, the alias of the target signature key, the path to the target signature certificate, the signature algorithm information, and the signature version information.

6. The APK signing method based on a hardware encryption card according to claim 2, characterized in that, The hardware encryption signature service has an internal concurrency control mechanism to limit multiple signature requests from accessing the hardware encryption card simultaneously. The concurrency control mechanism includes at least one of the following: mutex lock, task queue, single-threaded worker, distributed lock, and token scheduling mechanism.

7. The APK signing method based on a hardware encryption card according to claim 6, characterized in that, The hardware encryption signature service has a preset waiting time between two consecutive calls to the hardware encryption card to perform a signature operation, in order to avoid the hardware encryption card from malfunctioning due to rapid and continuous access.

8. The APK signing method based on a hardware encryption card according to claim 2, characterized in that, The hardware encryption signature service executes the signature by calling the private key in the hardware encryption card through the PKCS#11 interface.

9. The APK signing method based on a hardware encryption card according to claim 8, characterized in that, The hardware encryption signing service connects to the hardware encryption card through the SunPKCS11 provider and calls the apksigner tool to complete the APK signing.

10. The APK signing method based on a hardware encryption card according to claim 9, characterized in that, When calling the apksigner tool to sign an APK, the parameters used include provider-class, provider-arg, ks-type, ks-key-alias, ks-pass, the input APK path, and the output APK path.

11. The APK signing method based on a hardware encryption card according to claim 1, characterized in that, The hardware encryption card is a hardware security module or hardware encryption device that supports the PKCS#11 interface, including YubiKey and YubiHSM.

12. The APK signing method based on a hardware encryption card according to claim 1, characterized in that, The at least one key pair used for APK signing includes at least one of networkstack, platform, media, shared, testkey, and releasekey.

13. The APK signing method based on a hardware encryption card according to claim 1, characterized in that, The target private key for signing is determined from the key pair based on the build configuration of the APK to be signed, including: Read the Android.mk or Android.bp build file corresponding to the APK to be signed; When the build file contains LOCAL_CERTIFICATE or a corresponding certificate configuration item, the target private key is determined based on the certificate configuration item. If no certificate configuration item is configured in the build file, testkey or releasekey will be used as the target private key.

14. The APK signing method based on a hardware encryption card according to claim 2, characterized in that, The hardware encryption signing service is also used to accept secureboot firmware signing requests and call the hardware encryption card to complete the firmware signing.

15. The APK signing method based on a hardware encryption card according to claim 2, characterized in that, When the native APK signing module determines that the current signing task is an OTA package signing task, it retains the original OTA package signing process and does not send the signing task to the hardware encryption signing service.

16. An APK signing system based on a hardware encryption card, implementing the APK signing method based on a hardware encryption card as described in any one of claims 1-15, characterized in that, The system includes: A hardware encryption card is used to generate and save APK signing key pairs and export the X.509 certificate corresponding to the APK signing key pairs; The build configuration parsing module is used to parse the build configuration of the APK to be signed during the Android build process and determine the target private key for signing from the key pair; The signature flag detection module is used to detect whether hardware encryption card signature flags are enabled in the current compilation environment; The signature path switching module is used to switch the signing task of the APK to be signed from the local private key file signing path to the hardware encryption card signing path when the hardware encryption card signing mark is enabled. The signature execution module is used to call the hardware encryption card to perform a signature operation on the APK to be signed using the target private key, generate a signed APK file, and write the X.509 certificate corresponding to the target private key into the signed APK file.

17. The APK signing system based on a hardware encryption card according to claim 16, characterized in that, The signature path switching module includes: The native signature adaptation unit is used to send the signature request of the APK to be signed to an independent hardware cryptographic signature service; The hardware encryption signature service unit is used to receive the signature request and complete the signature by calling the target private key in the hardware encryption card through a concurrency control mechanism.

18. The APK signing system based on a hardware encryption card according to claim 17, characterized in that, The hardware encryption signature service unit includes: The interface receiving subunit is used to receive signature requests; The task scheduling subunit is used to queue and schedule multiple signature requests; A hardware access control subunit is used to control access to the hardware encryption card via a mutex lock; The signature execution subunit is used to call an APK signing tool that supports PKCS#11 to complete the APK signing; The result output sub-unit is used to output the signed APK file.