应用程序包常见问题

如何获取签名信息中的指纹信息

  • 通过调用接口获取。

可以调用bundleManager.getBundleInfoForSelf获取自身的BundleInfo应用包信息,应用包信息中包含signatureInfo签名信息,签名信息中包含指纹信息。

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
  bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
try {
  bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo:bundleManager.BundleInfo) => {
    console.info('testTag', 'getBundleInfoForSelf successfully. fingerprint: ', bundleInfo.signatureInfo.fingerprint);
  }).catch((err: BusinessError) => {
    console.error('testTag', 'getBundleInfoForSelf failed. Cause: ', err.message);
  });
} catch (err) {
  let message = (err as BusinessError).message;
  console.error('testTag', 'getBundleInfoForSelf failed: %{public}s', message);
}
hdc shell
# 需将com.example.myapplication替换为实际应用的包名
bm dump -n com.example.myapplication | grep fingerprint 

alt text

  • 通过.cer证书文件获取,可以参考APP备案FAQ中HarmonyOS应用/元服务如何获取公钥和签名信息。

  • 通过keytool工具获取,详情参考生成签名证书指纹

什么是appIdentifier

appIdentifier是Profile签名文件中的一个字段,为应用的唯一标识,在应用签名时生成,其中:

  1. 通过DevEco Studio工具自动签名生成,此时的appIdentifier字段是随机生成的,在不同的设备上签名、或者重新签名均会导致appIdentifier字段不一致。
  1. 手动配置签名,详情参考应用包签名工具指导,此时appIdentifier字段取值为HarmonyAppProvision配置文件中app-identifier字段。

因此,在跨设备调试、跨应用交互调试、或者多用户共同开发且需要共享密钥等要求appIdentifier不变的场景下,推荐使用手动签名,具体场景请参考使用场景说明

如何获取应用信息中的appIdentifier

  • 可以调用bundleManager.getBundleInfoForSelf获取自身的BundleInfo应用包信息,应用包信息中包含signatureInfo签名信息,签名信息中包含appIdentifier信息。
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
  bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
try {
  bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo:bundleManager.BundleInfo) => {
    console.info('testTag', 'getBundleInfoForSelf successfully. appIdentifier:', bundleInfo.signatureInfo.appIdentifier);
  }).catch((err: BusinessError) => {
    console.error('testTag', 'getBundleInfoForSelf failed. Cause:', err.message);
  });
} catch (err) {
  let message = (err as BusinessError).message;
  console.error('testTag', 'getBundleInfoForSelf failed:', message);
}
hdc shell
# 需将com.example.myapplication替换为实际应用的包名
bm dump -n com.example.myapplication | grep appIdentifier

alt text

什么是appId

appId是应用的唯一标识,由包名、下划线和证书公钥的Base64编码组成。由于appId和签名信息相关,如果签名证书的公钥更换,appId也会跟随变化,所以应用的唯一标识推荐使用appIdentifier

如何获取应用信息中的appId

  • 可以调用bundleManager.getBundleInfoForSelf获取自身的BundleInfo应用包信息,应用包信息中包含signatureInfo签名信息,签名信息中包含appId信息。
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
  bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
try {
  bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo:bundleManager.BundleInfo) => {
    console.info('testTag', 'getBundleInfoForSelf successfully. appId:', bundleInfo.signatureInfo.appId);
  }).catch((err: BusinessError) => {
    console.error('testTag', 'getBundleInfoForSelf failed. Cause:', err.message);
  });
} catch (err) {
  let message = (err as BusinessError).message;
  console.error('testTag', 'getBundleInfoForSelf failed:', message);
}
hdc shell
# 需将com.example.myapplication替换为实际应用的包名
bm dump -n ohos.app.hap.myapplication |grep '"appId":'

alt text