不建议在 APK 中存储密码。当我们谈论密钥库密码时,还有更多内容。是的,攻击者可以并且将会找到读取密码的方法,因为这就是他们所做的。鲁莽地阅读 APK 中包含的密码。假设您使用 gradle,有一种使用 gradle 指定如何存储密钥库密码的方法。
属性文件
如果您使用版本控制,请修改您的.gitignore
要排除的文件keystore.properties
,这是一个包含您的密码的文件。然后将其推送到存储库中。这样做将阻止共享项目中的其他开发人员了解密钥库详细信息。您现在可以创建实际的keystore.properties
文件位于项目的根目录中。该文件应包含以下内容:
keyAlias yourKeyAlias
keyPassword yourKeyPassword
storeFile pathOfYourKeyStoreFile
storePassword passwordOfYourKeyStoreFile
GRADLE
设置完您的keystore.properties
文件中,通过在外部定义属性变量来修改模块级 gradle 构建文件android { ... }
条款例如:
def keystorePropertiesFile= rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android { ... }
Inside android { ... }
, 宣布signingConfigs { ... }
这样:
android {
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
...........
}
最后还是在里面android { ... }
在你的模块级 gradle 构建文件中,你应该有buildTypes { ... }
子句包含debug { ... }
and release { ... }
配置为默认。修改release
配置使得:
buildTypes {
debug {
*insert debug configs here*
}
release {
*insert release configs here*
signingConfig signingConfigs.config
}
}
定义signingConfig signingConfigs.config
in release { ... }
每当您选择创建发布版本时,将允许您自动签署您的 APK,所有这些都无需在 APK 中存储您的密钥库密码。干杯!