六、keytool工具

一个keytool的小工具.配置配置参数,挺方便希望能帮到大家.已经测试过的.keystore和jks都可以用

# -*- coding: utf-8 -*-
import os
import shutil

KEY_LOCATION = "/Users/test/Documents/Android_workspace/Dancing/app/debug.jks"
KEY_ALIAS = "debug.jks"
KEY_PWD = "test123" #password
KEY_STORE_PWD = "test123" #storepass
KEY_DAYS = 10000  #keystore的有效期
KEY_NEWPWD = "newtest123"  # 需要修改keystore才需要配置

KEY_OPTION = 3  # 1生成   2查询md5 sha1  3修改keystore


# 初始化一些变量
def readonly_handler(func, path, execinfo):
    os.chmod(path, 128)
    func(path)

#生成keystore
def generateKeyStore():
    if os.path.exists(KEY_LOCATION):
        os.remove(KEY_LOCATION);
    generateCommond = " keytool -genkey -alias " + KEY_ALIAS + " -keypass " + KEY_PWD + " -keyalg RSA -keysize 1024 -validity " + KEY_DAYS.__str__() + " -keystore  " + KEY_LOCATION + " -storepass " + KEY_STORE_PWD + " -dname 'CN=test OU = 组织单位名称, O = 组织名称, L = 城市或区域名称, ST = 州或省份名称, C = cn'"
    os.system(generateCommond);

#获取keystore的sha1 md5
def getKeyStoreFinger():
    getFingerCommond = "keytool -list -v -keystore " + KEY_LOCATION + " -storepass " + KEY_STORE_PWD
    os.system(getFingerCommond)

#修改keystore
def modifyKeyStore():
    modifyKeyStoreCommond = " keytool -storepasswd -keystore " + KEY_LOCATION + " -storepass " + KEY_LOCATION + " -new " + KEY_NEWPWD
    os.system(modifyKeyStoreCommond)


if (KEY_OPTION == 1):
    generateKeyStore()
elif (KEY_OPTION == 2):
    getKeyStoreFinger()
elif (KEY_LOCATION == 3):
    modifyKeyStore()

你可能感兴趣的:(keytool,keystore,jks,python,androidstu,python)