- 传统方案未安装包太大,导致获取签名时间过长
- 改进方案,读取cert.rsa签名文件,提取签名信息,与安装包的签名做比对
- 传统方案在1G以上安装的测试与改进方案的测试结果
发现改进方案只要500多毫秒,传统方案要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);//第一块内容
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};
}
}