Android 在java中以编程方式对Apk文件进行签名

Android 在java中以编程方式对Apk文件进行签名,android,code-signing,android-source,Android,Code Signing,Android Source,我需要修改/data/app文件夹中现有的.apk文件。修改后,Meta INF文件夹中的签名会发生更改。因此,为了确保apk正常工作,我需要用正确的md5sum辞退他们 是否可以通过java编程退出APK,仅通过代码生成私钥和证书?我正在使用Bouncy Castle和此。重新签名示例: SignedJar bcApk = new SignedJar( new FileOutputStream("out.apk"), signChain, signCert, signKey); Jar

我需要修改
/data/app
文件夹中现有的.apk文件。修改后,Meta INF文件夹中的签名会发生更改。因此,为了确保apk正常工作,我需要用正确的md5sum辞退他们


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

我正在使用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();
SignedJar bcApk=newsignedjar(
新的FileOutputStream(“out.apk”)、signChain、signCert、signKey);
JarFile jsApk=新的JarFile(新文件(“in.apk”);
枚举条目=jsApk.entries();
while(entries.hasMoreElements()){
JarEntry=entries.nextElement();
String name=entry.getName();
if(!entry.isDirectory()&&!name.startsWith(“META-INF/”){
InputStream eis=jsApk.getInputStream(条目);
bcApk.addFileContents(名称,IOUtils.toByteArray(eis));
eis.close();
}
}
jsApk.close();
bcApk.close();

@Yury任何帮助都会非常感激。