今天遇到一个需求。获取全部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. 375 Guess Number Higher or Lower II 猜数字大小 II

    我们正在玩一个猜数游戏,游戏规则如下:我从 1 到 n 之间选择一个数字,你来猜我选了哪个数字.每次你猜错了,我都会告诉你,我选的数字比你的大了或者小了.然而,当你猜了数字 x 并且猜错了的时候,你需 ...

  2. Java 8 (10) CompletableFuture:组合式异步编程

    随着多核处理器的出现,提升应用程序的处理速度最有效的方式就是可以编写出发挥多核能力的软件,我们已经可以通过切分大型的任务,让每个子任务并行运行,使用线程的方式,分支/合并框架(java 7) 和并行流 ...

  3. [ 东莞市选 2008 ] GCD&LCM

    \(\\\) \(Description\) 给出两数的\(GCD\)和\(LCM\),求合法的两数之差的绝对值最小是多少. \(GCD\times LCM\le10^{18}\) \(\\\) \( ...

  4. npm err报错解决

    最近看vue官网:按照官网步骤正确按照vue脚手架却报错 翻了很多,才发现是webpack的问题 npm install webpack-dev-server@2.9.7 --save ok,好了!

  5. 树莓派GPIO点亮第一个led

    代码如下: 注意:::::此时的GPIO口为18编号口而非GPIO18 import RPi.GPIO as GPIO //引入函数库 import time RPi.GPIO.setmode(GPI ...

  6. Python中深拷贝与浅拷贝的区别

    转自:http://blog.csdn.net/u014745194/article/details/70271868 定义: 在Python中对象的赋值其实就是对象的引用.当创建一个对象,把它赋值给 ...

  7. http协议对照表

    1**:请求收到,继续处理 2**:操作成功收到,分析.接受 3**:完成此请求必须进一步处理 4**:请求包含一个错误语法或不能完成 5**:服务器执行一个完全有效请求失败 100——客户必须继续发 ...

  8. java正则表达式匹配字符

    假设要匹配${2}中间为数字的这个类型的变量String,则 Pattern p = Pattern.compile("\\$\\{\\d+\\}"); Matcher m = p ...

  9. CodeFrist基础_Fluent Api

    一丶首先新建两个实体类 public class Student { public int StudentKey { get; set; } public string StudentName { g ...

  10. POJ2152 Fire (树形DP)

    题意:n个城市n-1条边 组成一棵树 在每个城市修建消防站会有一个花费costi 每个城市能防火当且仅当地图上距离他最近的消防站距离小于di   问如何修建消防站 使地图上所有的城市都有预防火灾的能力 ...