今天遇到一个需求。获取全部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. 372 Super Pow 超级次方

    你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出.示例 1:a = 2b = [3]结果: 8示例 2:a = 2b = [1,0]结果: 102 ...

  2. 在dataGridView空间中添加数据

    //查询信息sql语句 string sql = "select studentName,addres from student"; SqlDataAdapter adapter ...

  3. Objective-C设计模式——适配器Adapter(接口适配)

    适配器模式 适配器模式通俗来讲,其实就是对客户端添加新的类但却不修改客户端和新的类的接口.此时我们需要自己来实现适配,在适配器模式中有Target对象,即客户端所需要的接口对象,Adaptee对象,即 ...

  4. windows系统下的redis启动教程

    下载解压后配置redis.conf文件配置端口号和密码,打开poweshell命令,进入redis解压目录,使用.\redis-server.exe redis.conf 命令启动redis服务,再打 ...

  5. [Windows Server 2012] MySQL更改数据库引擎(MyISAM改为INNODB)

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:更改MyS ...

  6. sql的for update

    欢迎大家吐槽 oracle行级共享锁 通常是通过select … from for update语句添加的,同时该方法也是我们用来手工锁定某些记录的主要方法.比如,当我们在查询某些记录的过程中,不希望 ...

  7. docker 1-->docker swarm 转载

    实践中会发现,生产环境中使用单个 Docker 节点是远远不够的,搭建 Docker 集群势在必行.然而,面对 Kubernetes, Mesos 以及 Swarm 等众多容器集群系统,我们该如何选择 ...

  8. git学习(3)----git 新建分支并提交本地代码到远程分支

    一.步骤 1.在gitlab上创建一个issue,issue一般来说是版本发布说明.比如本次更新了什么功能,修复了什么bug什么的. 2.然后在本地创建一个branch,或者直接在gitlab上申请m ...

  9. JAVA基础——Date和Calendar类

    1计算某一月份的最大天数 Calendar time=Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR,year); //yea ...

  10. springmvc学习及源码地址

    http://jinnianshilongnian.iteye.com/blog/1634096