Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store API keys on Swift?

I have a bunch of API keys and secrets (Stripe, Cloudinary etc), that are currently hard coded in my app. Where is the right place to store them? Should they be in the server, and I just store the server URL at my end (so that if the keys changes, the app continues to work)?

for example, I have this in my app delegate file:

    func configureStripe(){
            STPPaymentConfiguration.sharedConfiguration().publishableKey = "pk_test_1234rtyhudjjfjjs"         

STPPaymentConfiguration.sharedConfiguration().appleMerchantIdentifier = "merchant.com.myapp"
    }
like image 731
Prabhu Avatar asked Feb 18 '17 05:02

Prabhu


People also ask

Where should I store my API keys?

Instead of embedding your API keys in your applications, store them in environment variables or in files outside of your application's source tree.

Should API keys be stored in database?

Storage: API keys should not be stored as plain text but rather stored as a hashed value in the database to prevent copying. Even if an attacker successfully targets the key management database, the keys are unusable.

What do I do with my API key?

API keys can be used to identify a specific project or the application making the call to the API. While API keys are not as secure as the tokens that provide authentication, they help identify the project or application that makes the call.


1 Answers

There are many tools to store secret keys.

  1. https://nshipster.com/secrets/
  2. https://www.freecodecamp.org/news/how-to-securely-store-api-keys-4ff3ea19ebda/

If personal project, I typically go with xccconfig and just ignore that file in git but with teams this can be quite hard.

like image 118
Tim Avatar answered Sep 21 '22 15:09

Tim