0
点赞
收藏
分享

微信扫一扫

安全篇 - 隐式配置 KeyStore 签名信息


LZ-Says:技术的魅力,非几句言语可表述~ 需要细细品味~!


安全篇 - 隐式配置 KeyStore 签名信息_微信支付

前言

还记得,在某司对接支付,Enmmm,微信支付的时候,申请时提交的是正式证书的信息,所以想测试,只能使用正式签名才可以。

问题 LZ 只是想玩玩,又不是提交测试。肿么破?

最后想想,直接指定签署 Debug Apk 时使用正式签名不就好了,小手一点运行,简直6的不要不要的。

debug {
try {
storeFile file("keystore address")
storePassword "your password"
keyAlias "your alias"
keyPassword "your key password"
} catch (ex) {
throw new InvalidUserDataException(ex.toString())
}
}

Enmmm,虽然最后也发现了还可以修改证书,下面附上地址链接:


Enmmm,还以为以后就这样咯,结果今天看到官方,不免得为当初 Low 的举动腹黑一波~

开车

这里,引用一波官方的说明:

在创建签名文件时,Android Studio 会以纯文本形式将签名信息添加到模块的 build.gradle 文件中。如果是团队协作开发或者将代码开源,那么应当将此敏感信息从构建文件中移出,以免被其他人轻易获取。为此,我们应创建一个单独的属性文件来存储安全信息并按以下步骤操作,在我们的构建文件中引用该文件。

具体操作步骤如下:

Step 1: 在项目的根目录下创建一个名为 keystore.properties 的文件。此文件应当包含签名信息,如下所示:

storePassword = yourStorePassword
keyPassword = yourkeyPassword
keyAlias = yourKeyAlias
storeFile = yourStoreFileLocation

Step 2: 在模块的 build.gradle 文件中,于 android {} 块的前面添加用于加载 keystore.properties 文件的代码,随后修改配置中的引用即可。

// 创建一个名为keystorePropertiesFile的变量,并将其初始化为rootProject文件夹中的keystore.properties文件。
def keystorePropertiesFile = rootProject.file("keystore.properties")

// 初始化一个名为keystoreProperties的新Properties()对象
def keystoreProperties = new Properties()

// 将keystore.properties文件加载到keystoreProperties对象中
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
...
// 签名配置
signingConfigs {
config{
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
keyAlias keystoreProperties['keyAlias'] // 这块也可以使用:keystoreProperties.getProperty()
keyPassword keystoreProperties['keyPassword']
}
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
signingConfig signingConfigs.config
}
}
...
}

Enmmm,最后点击 Build > Build APK 以构建发布 APK ,并确认 Android Studio 已在模块的 build/outputs/apk/ 目录中创建一个签署的 APK。

感受

还是要多看看官方文档,真的是能学习不少东西。

别人搞得在6,终究是别人的。

参考资料

  1. ​​https://developer.android.google.cn/studio/publish/app-signing​​;

个人公众号

不定期发布博文,感谢大家关注~


安全篇 - 隐式配置 KeyStore 签名信息_微信支付_02


举报

相关推荐

0 条评论