关于已安装包和未安装包签名比对的问题

  1. 传统方案未安装包太大,导致获取签名时间过长
  2. 改进方案,读取cert.rsa签名文件,提取签名信息,与安装包的签名做比对
  3. 传统方案在1G以上安装的测试与改进方案的测试结果
image.png

发现改进方案只要500多毫秒,传统方案要50秒左右

  1. 代码
    package com.signature;

import java.io.ByteArrayInputStream;

public class SignatureBlock {

public static byte[] decode(byte[] bytes) {
   ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
   readBlockNoContent(bais, false);//第一块
   readBlockNoContent(bais, true);//第一块内容
   readBlockNoContent(bais, false);//第二块
   readBlockNoContent(bais, false);//第三块
   readBlockNoContent(bais, true);//第三块内容1
   readBlockNoContent(bais, true);//第三块内容2
   readBlockNoContent(bais, true);//第三块内容3
   int[] signature = readBlockNoContent(bais, false);//第四块
   bytes = new byte[signature[2]];
   bais.read(bytes, 0, bytes.length);
   return bytes;
}

public static int check_length(ByteArrayInputStream bais, int check_length) {
   if (check_length < 0x80)
      return check_length;
   int bit_low = check_length & 0x7f;
   if (bit_low == 1) {
      return bais.read();
   } else if (bit_low == 2) {
      return bais.read() * 256 + bais.read();
   } else if (bit_low == 3) {
      return bais.read() * 256 * 256 + bais.read() * 256 + bais.read();
   } else {
      return -1;
   }
}

public static int[] readBlockNoContent(ByteArrayInputStream bais, boolean skip) {
   int tag          = bais.read();
   int check_length = bais.read();
   int length       = check_length(bais, check_length);
   if (skip) {
      bais.skip(length);
   }
   return new int[]{tag, check_length, length};
}

}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容