比较签名的问题

时间:2016-10-13 06:35:09

标签: java

我在比较两个签名值时遇到了问题。从日志中获取两个值相同但仅输入else语句。

private static final String SIGNATURE = "TLFjqb41Fg+W/qAEw7GMefvr2VY=";

PackageInfo packageInfo = context.getPackageManager()
     .getPackageInfo(context.getPackageName(),
          PackageManager.GET_SIGNATURES);

for (Signature signature : packageInfo.signatures) {
    byte[] signatureBytes = signature.toByteArray();

    MessageDigest md = MessageDigest.getInstance("SHA");

    md.update(signature.toByteArray());

    final String currentSignature = Base64.encodeToString(md.digest(), Base64.DEFAULT);

    Log.d("REMOVE_ME", "Include this string as a value for SIGNATURE " + currentSignature);
    Log.d("REMOVE_ME", "SIGNATURE as a value for SIGNATURE value:" + SIGNATURE);

    //compare signatures

    if (SIGNATURE.equals(currentSignature)){
        Log.d("REMOVE_ME", "in  IF loop");
        return VALID;

    }else{
        Log.d("REMOVE_ME", "in  else loop");
        return INVALID;
    }

获取日志:

10-13 11:52:27.801: D/REMOVE_ME(16873): Include this string as a value for SIGNATURE TLFjqb41Fg+W/qAEw7GMefvr2VY=
10-13 11:52:27.801: D/REMOVE_ME(16873): SIGNATURE as a value for SIGNATURE value:TLFjqb41Fg+W/qAEw7GMefvr2VY=
10-13 11:52:27.801: D/REMOVE_ME(16873): in  else loop

0 个答案:

没有答案