Android 读取APK签名信息
来源:互联网 发布:剑网三脸型数据成男 编辑:程序博客网 时间:2024/05/17 03:42
- 某些时候需要获取某个特定的apk(已安装或者未安装)的签名信息,如程序自检测,可信赖的第三方检测(应用市场),系统限定安装
- 对此,有两种实现方法
- 可以使用Java自带的API(主要用到的为JarFile,JarEntry,Certificate)进行获取,还有一种方法是使用系统隐藏的API PackageParser,通过反射来使用对应的API.
- 但是由于安卓系统的分裂版本过多,并且不同厂商进行的修改很多,依赖反射隐藏API的方法并不能保证兼容性和通用性,因此推荐使用JAVA自带API进行获取:
- /**
- * 从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);
- }
0 0
- Android 读取APK签名信息
- Android 读取APK签名信息
- android 读取apk签名信息
- Android 读取APK签名信息
- Android 读取APK签名信息
- Android 读取APK签名信息
- Android 如何读取APK 签名信息
- Android:获取APK签名信息
- Android:获取APK签名信息 .
- Android Apk签名信息详解
- android apk 签名信息 相关
- android查看apk签名信息
- Android获取apk签名信息
- 如何读取APK中的签名信息
- android读取应用签名信息
- JAVA 读取APK包信息以及签名信息
- 获取Android的APK包签名信息
- Android查看apk签名信息方法
- ActiveMQ(中文)参考手册
- Android兑现ImageView加边框
- 将排序二叉树转化成双向链表
- Qt creator常用快捷键
- Virtual Disk "hard disk 3' is not accessible on the host 虚拟机不能启动的解决方法
- Android 读取APK签名信息
- xilinx 下调用锁相环IP出错
- 鼠标拖动一个文件路径 到TextBox中显示
- 高手必学规程!!
- 感悟
- 一段文件相关的shell脚本解读
- 权责发生制
- oracle 自增字段 以及插入包含自增字段的过程
- 顺序表(动态分配空间)