在Java编程签名APK档案 [英] Signing Apk files programmatically in java

查看:200
本文介绍了在Java编程签名APK档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改preexisting .apk文件中的 /数据/应用程序文件夹的文件present。修改后的签名在 META-INF 文件夹更改。因此,为了确保APK正常工作,我需要用正确的md5sum辞职它们。

I need to modify preexisting .apk files present in the /data/app folder. After the modifications the signatures change in the Meta-INF folder. So in order to make sure the apk works properly I need to resign them with the correct md5sum.

是否有可能通过Java编程辞职的APK,产生通过code私钥和证书只?

Is it possible to resign the apks programmatically through java, generating private key and certs through code only?

推荐答案

我使用的充气城堡,这。再签收例如:

I am using Bouncy Castle and this class. Re-sign example:

SignedJar bcApk = new SignedJar(
    new FileOutputStream("out.apk"), signChain, signCert, signKey);
JarFile jsApk = new JarFile(new File("in.apk"));
Enumeration<JarEntry> entries = jsApk.entries();
while (entries.hasMoreElements()) {
    JarEntry entry = entries.nextElement();
    String name = entry.getName();
    if (!entry.isDirectory() && !name.startsWith("META-INF/")) {
        InputStream eis = jsApk.getInputStream(entry);
        bcApk.addFileContents(name, IOUtils.toByteArray(eis));
        eis.close();
    }
}
jsApk.close();
bcApk.close();

这篇关于在Java编程签名APK档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆