Android 生成Keystone,对Apk进行二次签名

一、创建Keystone

方式一:运行bat

CreateKeystone

方式二:执行java

package com.uiuno.createkeystone;

import java.io.File;
import java.io.IOException;

public class CreateKeystone {
	
	private static String keystore = "G:\\pdragon_tools\\CreateKeystone\\debug.keystore";	//keystone名称
	private static String alias = "debug.keystore";				//keystone别名
	private static String storepass = "uiunopl";			//密码
	private static String keypass = "uiunopl";			//密码
	private static String keyalg = "RSA";				//加密方式
	private static String keysize = "2048";				//长度
	private static String validity = "10000";			//有效天数
	private static String CN = "uiuno";			        //名字
	private static String OU = "uiuno";					//单位
	private static String O = "uiuno";					//组织
	private static String L = "WuHan";					//城市
	private static String ST = "HuBei";					//省份
	private static String C = "CN";						//国家
	
	public static void main(String[] args) {
		 try {
			File file = new File(keystore);
			if(file.exists()){
				file.delete();
			}
			Process process = Runtime.getRuntime().exec(getCmd());
			System.out.println("生成成功");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("生成失败");
		}
	}
	
	private static String getCmd(){
		
		String cmd = "keytool -genkey -keystore "+ keystore +" -alias "+ alias +" -storepass "+ storepass +" -keypass "+ keypass +" -keyalg "+ keyalg 
				+" -keysize "+ keysize + " -validity "+ validity +" -dname \"CN='"+ CN +"', OU='"+ OU +"', O='"+ O +"', L='"+ L +"', ST='"+ST+"', C='"+ C +"'\"";
		System.out.println("CMD:" + cmd);
		return cmd;
	}
	
	
}

二、删除apk中的META-INF文件夹。

把apk用360压缩工具解压,把里面的META-INF文件夹删除,然后在压缩,并改名成apk

三、重新签名

jarsigner -verbose -keystore debug.keystore -signedjar com.demo.apk puzzlebo_ppss_wedobest_xiaomi_yumi_pay_ads_v1.00.apk debug.keystore

-keystore debug.keystore:签名文件

-signedjar com.demo.apk puzzlebo_ppss_wedobest_xiaomi_yumi_pay_ads_v1.00.apk debug.keystore:需要二次签名的apk和 keytone别名

java执行为:

package com.uiuno.createkeystone;

import java.io.File;
import java.io.IOException;

public class SignApk {
	
	private static String apk = "puzzlebo_ppss_wedobest_xiaomi_yumi_pay_ads_v1.00.apk";	//keystone名称
	private static String keystore = "debug.keystore";			//keystone名称
	private static String alias = "debug.keystore";				//keystone别名
	private static String storepass = "uiunopl";				//密码
	private static String keypass = "uiunopl";					//密码
	private static String keyalg = "RSA";						//加密方式
	
	public static void main(String[] args) {
		 try {
			Process process = Runtime.getRuntime().exec(getCmd());
			System.out.println("二次签名成功");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("二次签名失败");
		}
	}
	
	private static String getCmd(){
		// jarsigner -verbose -keystore demo.keystore -signedjar demo_signed.apk demo.apk demo.keystore
		String cmd = "jarsigner -verbose -keystore "+keystore+" -signedjar "+ apk +" "+ alias;
		System.out.println("CMD:" + cmd);
		return cmd;
	}
	
	
}

 

0 条评论
发表一条评论