3

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.

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

0

1 Answer 1

6

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.