3

我需要修改文件夹中现有的 .apk 文件/data/appMeta-INF修改后,文件夹中的签名会发生变化。因此,为了确保 apk 正常工作,我需要使用正确的 md5sum 对它们进行签名。

是否可以通过java以编程方式退出apks,仅通过代码生成私钥和证书?

4

1 回答 1

6

我正在使用 Bouncy Castle 和这个。重新签名示例:

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();
于 2014-04-12T21:51:18.777 回答