今天遇到一个需求。获取全部apk的签名的MD5。以下是我使用Java SE实现的一个工具。贴出核心源码。希望给有须要的朋友有所帮助。

界面例如以下:

仅仅须要制定.apk文件所在的文件夹就可以,核心代码例如以下:

public class ReadCmdLine {
private static MD5Window window;
private static String inputPath; public static void main(String args[]) {
window = new MD5Window();
window.setVisible(true);
initWindow();
} private static void initWindow() {
// 文件文件夹文本框
window.getFilePathButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.showDialog(new JLabel(), "选择");
File file = jfc.getSelectedFile();
notDirectoryExcute(file);
}
});
// 開始运行button
window.getBeginButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
inputPath = window.getJTextFiled();
if (inputPath != null && !"".equals(inputPath.trim())) {
notDirectoryExcute(new File(inputPath));
}
}
});
// 清空结果button
window.getClearButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
window.setTextArea("");
}
});
} /**
* 推断是否是文件夹,假设不是则运行
*
* @param file
*/
public static void notDirectoryExcute(File file) {
if (file.isDirectory()) {
inputPath = file.getAbsolutePath();
window.setJTextFiled(inputPath);
File[] fiels = file.listFiles();
for (int i = 0; i < fiels.length; i++) {
String absPath = fiels[i].getAbsolutePath();
if (absPath.contains(".apk")) {
excute(absPath);
}
}
} else {
JOptionPane.showMessageDialog(window, "请选择文件夹");
}
} /**
* 核心逻辑
*
* @param absPath
*/
public static void excute(String absPath) {
// 1、从.apk中读取CERT.RSA文件
String appName = absPath.substring(absPath.lastIndexOf("_") + 1,
absPath.lastIndexOf("."));
try {
if (absPath != null) {
readZipFile(absPath);
}
} catch (Exception e) {
e.printStackTrace();
}
// 2、运行 keytool命令获取MD5
Process process = null;
List<String> processList = new ArrayList<String>();
try {
process = Runtime.getRuntime().exec(
"keytool -printcert -file D:/test/CERT.RSA");
BufferedReader input = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line = "";
while ((line = input.readLine()) != null) {
processList.add(line);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
// 过滤内容
for (String line : processList) {
if (line.contains("MD5")) {
window.setTextArea(window.getTextArea()
+ String.format("%-30s", appName) + line.trim() + "\n");
}
}
} /**
* 读取压缩文件内容
*
* @param file 压缩文件的路径
* @throws Exception
*/
public static void readZipFile(String file) throws Exception {
ZipFile zf = new ZipFile(file);
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zin = new ZipInputStream(in);
File outFile = new File("D:\\test\\CERT.RSA");
OutputStream out = new FileOutputStream(outFile);
InputStream rsaStream = zf.getInputStream(zf
.getEntry("META-INF/CERT.RSA"));
byte[] buf1 = new byte[1024];
int len;
while ((len = rsaStream.read(buf1)) > 0) {
out.write(buf1, 0, len);
}
rsaStream.close();
out.close();
in.close();
zin.closeEntry();
}
}

JFrame实现批量获取Android安装包安全证书MD5的更多相关文章

  1. 技术|Android安装包优化

    版权声明 1.本文版权归原作者所有,转载需注明作者信息及原文出处. 2.本文作者:赵裕(vimerzhao),永久链接:https://github.com/vimerzhao/vimerzhao.g ...

  2. 技术|Android安装包极限优化

    版权声明 1.本文版权归原作者所有,转载需注明作者信息及原文出处. 2.本文作者:赵裕(vimerzhao),永久链接:https://github.com/vimerzhao/vimerzhao.g ...

  3. Android安装包相关知识汇总 (编译过程图给力)

    转自: https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=208008519&idx=1&sn=278b7793699 ...

  4. android 安装包签名问题探究

    1.首先先科普一下,android为什么需要给安装包签名: 所有的Android应用程序在发布之前都要求开发人员用一个证书进行数字签名,anroid系统不会安装没有进行签名的由于程序.    平时我们 ...

  5. Android安装包apk文件在某些版本操作系统上安装解析包出错问题的解决办法

    当我们将Android升级功能的中的下载新版本apk文件存放在data/data/xxx.apk位置时,在有的些版本的手机中安装可能会出现安装包解析出错的问题,对于该问题的解决方案是提升该文件的权限. ...

  6. Mac下获取AppStore安装包文件路径

    通过远在大洋彼岸的苹果服务器下载东西,确实有够慢啊!AppStore更甚:甚至都经常提示连不上服务器,而有些软件呢,还必须从AppStore下载安装,所以没办法,谁让上了苹果的贼船呢!公司的网速更是不 ...

  7. Mac下获取AppStore安装包文件路径-取出安装包

    问题描述:我们通过AppStore下载软件的时候想要把安装包保存下来,但是AppStore安装好之后会自动删除安装包,而且安装路径也很难找到. 解决方案: 一.打开活动监视器 二.找storedown ...

  8. unity 导出 android安装包配置方案

    原地址:http://blog.csdn.net/u012085988/article/details/17393111 1.jdk本人安装的是win32版的(虽然系统是64位的.但听说装64位的导出 ...

  9. [原]获取openstack-pike安装包

    linux version: CentOS 7.5.1804 #进入仓库配置目录 cd /etc/yum.repo.d/ #批量重命名所有文件 for files in `ls *`; do mv $ ...

随机推荐

  1. cloudera-agent启动File not found : /usr/sbin/cmf-agent解决办法(图文详解)

    不多说,直接上干货! 问题详情 bigdata@nssa-sensor1:~$ sudo service cloudera-scm-agent startFile not found : /usr/s ...

  2. java list遍历三种方法

    JSONArray jsonArray = new JSONArray(); jsonArray.add("1"); jsonArray.add("2"); j ...

  3. string与int的相互转换C++(转)

    string与int之间的相互转换C++(转) #include<iostream> #include<string> #include<sstream> usin ...

  4. [ SDOI 2006 ] 保安站岗

    \(\\\) Description 给出一棵 \(n\) 个节点以 \(1\) 为根的树,一个节点的覆盖半径是 \(1\) ,点有点权 \(val_x\) . 选择一些点,使得点权和最小,同时每个节 ...

  5. from scipy import spatial 出现 from .qhull import * ImportError: DLL load failed: The specified module could not be found. 错误

    错误描述: 本人机器window8.1 64位,python2.7. Traceback (most recent call last): File "C:/Users/Hamid/Docu ...

  6. CF821B Okabe and Banana Trees

    思路: 暴力枚举. 实现: #include <iostream> #include <cstdio> using namespace std; typedef long lo ...

  7. HanLP自然语言处理包开源(包含源码)

    支持中文分词(N-最短路分词.CRF分词.索引分词.用户自定义词典.词性标注),命名实体识别(中国人名.音译人名.日本人名.地名.实体机构名识别),关键词提取,自动摘要,短语提取,拼音转换,简繁转换, ...

  8. UIPageViewController 翻页、新手引导--UIScrollView:pagingEnabled

    UIPageViewController 翻页.新手引导--UIScrollView:pagingEnabled

  9. How a stack frame works 栈帧的要素与构建步骤

    http://en.citizendium.org/wiki/Stack_frame To use a stack frame, a thread keeps two pointers, often ...

  10. First Project -用函数写的ATM+购物商城程序

    作业需求:模拟实现一个ATM + 购物商城程序 额度15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日,过期未还,按欠 ...