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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With