将Android源码中的公私钥对转换为keystore的方法

本文介绍如何利用Google提供的四个标准key(testkey、platform、shared 和 media)之一的platform来生成keystore文件。文章详细展示了使用openssl和keytool这两个工具进行私钥格式转换及keystore创建的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前言
goolge为我们提供了4个标准的key,以签名测试程序:
testkey -- a generic key for packages that do not otherwise specify a key.
platform -- a test key for packages that are part of the core platform.
shared -- a test key for things that are shared in the home/contacts process.
media -- a test key for packages that are part of the media/download system.
它们位于Android源码的以下目录
android\build\target\product\security

使用eng选项即表示编译生成工程版的Android系统,
使用user选项时表示编译用户版(即正式版)的Android系统。

二、使用key生成keystore文件
使用google的标准key生成keystore文件。我们需要2个工具,openssl  (cryptography and SSL/TLS toolkit) and keytool
openssl是Linux上的一个工具,keytool则是JDK的一个工具,它位于JDK\bin目录。在此假设你已经把JDK\bin添加到了环境变量中。因为

在这里我将以platform为例进行讲解。
1.把build/target/product/security下面的某对需要转换的key拷贝到一个你的工作目录

2.执行:openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem
执行该命令,将platform.pk8格式的私钥转换成pkcs12格式的platform.pem文件

3.openssl pkcs12 -export -in  platform.x509.pem -out platform.p12 -inkey  platform.pem -password pass:android -name androiddebugkey
执行该命令,将生成密钥文件platform.p12 (注:此过程中需要输入密码:android)

4.keytool -importkeystore -deststorepass android -destkeystore platform.keystore -srckeystore platform.p12 -srcstoretype PKCS12 -srcstorepass android -destkeypass android -alias androiddebugkey


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值