久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

有沒有一種安全的方法來管理 API 密鑰?

Is there a safe way to manage API keys?(有沒有一種安全的方法來管理 API 密鑰?)
本文介紹了有沒有一種安全的方法來管理 API 密鑰?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在我的應用程序中使用 API.我目前從 java 接口管理 API 密鑰

I am using an API within my app. I currently manage the API key from a java interface

public interface APIContract {
    //The API KEY MUST NOT BE PUBLISH. It is possible to generate a new one for free from www.themoviedb.org
    //Remove before commit !!!
    String API_KEY = "abcdefghijklmnopqrstuvwxyz";
    /...
}

這可以完成工作.我可以使用 APIContract.API_KEY 訪問密鑰,但正如您在評論中看到的那樣,如果我使用 git 和公共存儲庫(我不打算發布此密鑰),這是不安全的.

This do the job. I can access the key using APIContract.API_KEY, but as you can see in the comment this is not safe if I use git and a public repository (I am not suppose to publish this key).

所以這是我的問題:是否可以將此密鑰移動到另一個我可以從我的應用程序輕松訪問但不會提交的地方?

So here is my question : is it possible to move this key in another place which I can easily access from my app but which will not be committed ?

我發現這個 線程使用 gradle 存儲密鑰,但我需要提交 build.gradle 文件,所以它不能完成這項工作.

I found this thread which use gradle to store the key, but I need to commit the build.gradle file so it does not do the job.

有人知道如何解決這個問題嗎?我在 stackoverflow 中沒有發現類似的問題,但也許我錯過了一些東西

Does someone know how to solve this problem ? I did not find similar problem in stackoverflow but maybe I missed something

編輯我喜歡將密鑰移到任何 Java 代碼之外的想法,因為其他人(可能是非技術人員)可以輕松管理他們自己的密鑰.我正在考慮使用像 settings.gradle 這樣的 gradle 文件.

EDIT I love the idea of moving the key outside any java code because other people (maybe non technical people) can easily manage their own key. I was thinking about using a gradle file like settings.gradle.

推薦答案

這是另一種方式:

將 API 密鑰放在構建機器/服務器可訪問的文件中,我們稱之為:

Place the API key in a file accessible to the build machine/server, we'll call it:

/usr/api_user/api_key1

有內容:

myApiKey = abcdefghijklmnopqrstuvwxyz

您現在將使用 `BuildConfig' gradle 對象訪問它.將您的代碼修改為:

You will now access it using the `BuildConfig' gradle object. Modify your code to this:

public interface APIContract {
    //The API KEY MUST NOT BE PUBLISH. It is possible to generate a new one for free from www.themoviedb.org
    //Remove before commit !!!
    String API_KEY = BuildConfig.MY_API_KEY;
    /...
}

然后在你的 build.gradle 中,添加如下內容:

Then in your build.gradle, add something like this:

buildConfigField "String", "MY_API_KEY", getMyApiKey("myApiKey")

還要加上這個:

//return a MY API KEY from a properties file.
def getMyApiKey(String property){
    Properties properties = new Properties()
    properties.load(new FileInputStream("/usr/api_user/api_key1"))
    return """ + properties.getProperty(property) +"""
}

如您所知,您可以重新定位 API 目錄位置,使其不屬于您的存儲庫.當然,然后它將具有構建的文件系統依賴項......您可以在 CI/CD 環境(可能是像 Jenkins 之類的工具)中設置一個列表,以將構建文件復制到私有存儲庫,以進行備份.

You can relocate the API directory location, as you can tell, so that it is not a part of your repo. Of course, then it will have file system dependencies for the build... which you could have a list setup in a CI/CD environment (maybe a tool like Jenkins) to replicate the build files to a private repo, for backup purposes.

這篇關于有沒有一種安全的方法來管理 API 密鑰?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當前風味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風味庫的多風味應用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 国产免费高清 | 亚洲九色 | 久久精品色视频 | av午夜电影 | 97在线观视频免费观看 | 国产在线网站 | 九九久久久 | 日韩一区二区在线视频 | 国产精品久久久久久久久久久久久 | 成人午夜精品一区二区三区 | 亚洲a毛片 | 乳色吐息在线观看 | 午夜免费视频 | 蜜月aⅴ免费一区二区三区 99re在线视频 | 成人免费网站视频 | 久久av综合 | 欧美看片 | 国产精品久久久久久久久久免费看 | 欧美国产中文字幕 | 午夜寂寞福利视频 | 欧美一级免费看 | 亚洲综合小视频 | 中文字幕视频在线看5 | 欧美中文字幕 | 国产成人精品一区二区三 | 亚洲视频免费在线播放 | 国产小视频在线 | 成人在线视频看看 | 国产精品久久久久婷婷二区次 | 伊人导航 | 一区二区三区四区在线 | 免费九九视频 | 亚洲日本中文 | 亚洲综合一区二区三区 | 亚洲欧美日韩在线 | 午夜手机在线视频 | 亚洲国产精品一区二区三区 | 婷婷久| www.伊人.com | 成人av免费在线观看 | 一区二区三区中文字幕 |