Firebase 服务器密钥隐藏

问题描述 投票:0回答:1

我正在使用 android studio Java,我创建了一个聊天应用程序并且一切正常,包括 Firebase 推送通知,但是在我将我的应用程序上传到 playstore 之前,出于安全原因,我需要从代码中隐藏我的服务器密钥,以保护我的代码免受逆向工程和反编译器。有没有关于如何保护我的服务器密钥的教程?

我使用了混淆器,但我知道我的服务器密钥仍然不安全。

java decompiler
1个回答
0
投票

您可以在

ApiKey
中保护您的
Android Studio
。这不是 100% 安全的方式,但这使得在逆向工程中获得
ApiKey
变得太困难了。 (来源:videoUrl

第1步:

build.gradle(Module:app)

中添加此代码
android {
namespace 'com........fire'
compileSdk 33

defaultConfig {
    applicationId "com...........fire"
    minSdk 21
    targetSdk 33
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"


    //Step:1 below code for hide API KEY
    Properties properties= new Properties();
    properties.load(project.rootProject.file("local.properties").newDataInputStream());
    buildConfigField "String","API_KEY_DBNAME","\"${properties.getProperty("API_KEY_DBNAME")}\""
    //now add value of this ApiKey in > local.properties(SDK Location) file<<
}

第 2 步: 添加

local.properties(SDK Location)
[设置您要隐藏的 ApiKey/Url/Firebase 数据库名称]

# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C\:\\Users\\hp\\AppData\\Local\\Android\\Sdk

#Step:2 add your API url here
API_KEY_DBNAME=dbTwoInput

现在在 Java 文件中的任何地方获取您的 Api 密钥(在获取价值之前

Rebuild
您的项目

String apiKeyDbName= BuildConfig.API_KEY_DBNAME;

© www.soinside.com 2019 - 2024. All rights reserved.