關(guān)于已安裝包和未安裝包簽名比對的問題

  1. 傳統(tǒng)方案未安裝包太大,導(dǎo)致獲取簽名時間過長
  2. 改進方案,讀取cert.rsa簽名文件,提取簽名信息,與安裝包的簽名做比對
  3. 傳統(tǒng)方案在1G以上安裝的測試與改進方案的測試結(jié)果
image.png

發(fā)現(xiàn)改進方案只要500多毫秒,傳統(tǒng)方案要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);//第一塊內(nèi)容
   readBlockNoContent(bais, false);//第二塊
   readBlockNoContent(bais, false);//第三塊
   readBlockNoContent(bais, true);//第三塊內(nèi)容1
   readBlockNoContent(bais, true);//第三塊內(nèi)容2
   readBlockNoContent(bais, true);//第三塊內(nèi)容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};
}

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容