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

image.png
發(fā)現(xiàn)改進方案只要500多毫秒,傳統(tǒng)方案要50秒左右
- 代碼
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};
}
}