/**
* 从APK中读取签名
* @param file
* @return
* @throws IOException
*/
private static List<String> getSignaturesFromApk(File file) throws IOException {
List<String> signatures=new ArrayList<String>();
JarFile jarFile=new JarFile(file);
try {
JarEntry je=jarFile.getJarEntry("AndroidManifest.xml");
byte[] readBuffer=new byte[8192];
Certificate[] certs=loadCertificates(jarFile, je, readBuffer);
if(certs != null) {
for(Certificate c: certs) {
String sig=toCharsString(c.getEncoded());
signatures.add(sig);
}
}
} catch(Exception ex) {
}
return signatures;
}
/**
* 加载签名
* @param jarFile
* @param je
* @param readBuffer
* @return
*/
private static Certificate[] loadCertificates(JarFile jarFile, JarEntry je, byte[] readBuffer) {
try {
InputStream is=jarFile.getInputStream(je);
while(is.read(readBuffer, 0, readBuffer.length) != -1) {
}
is.close();
return je != null ? je.getCertificates() : null;
} catch(IOException e) {
}
return null;
}
/**
* 将签名转成转成可见字符串
* @param sigBytes
* @return
*/
private static String toCharsString(byte[] sigBytes) {
byte[] sig=sigBytes;
final int N=sig.length;
final int N2=N * 2;
char[] text=new char[N2];
for(int j=0; j < N; j++) {
byte v=sig[j];
int d=(v >> 4) & 0xf;
text[j * 2]=(char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
d=v & 0xf;
text[j * 2 + 1]=(char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
}
return new String(text);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有