How to Store API Keys Safely in Notes and Code

A key stored as a string remains part of your source code. Proven encryption offers a different way to store that value. AES-GCM can encrypt a key for storage and decrypt it when needed.1
Why plain text API keys are risky
An API key identifies a user or program and grants access to an API. It often acts as a secret token, with access tied to that identity. Keys also help track and control API use.2
Someone with your key can use the API as if they were you. You may be held responsible for their misuse.2
A public key can lead to charges you did not expect. It can also allow access to your data without your consent.3
Do not leave secrets unencrypted in code repositories or share them as plain text in messages. Keys in client code or repositories are open to theft.4, 3
A key placed in a request URL can be stolen through URL scans. For Google APIs, use the x-goog-api-key header or a client library instead.3
Common storage traps
Do not store an API key as a string in source code. Do not put it in Info.plist or a .xcconfig file used to fill Info.plist.1
An environment variable is not safe if it puts the key into code at compile time. That process still leaves the value as a string in your code.1
Base64 and Base32 do not make an API key safe. Simple XOR is not safe protection either. Use a proven method such as AES-GCM instead.1
Most tools that obscure code are not safe encryption on their own. They can be better than leaving passwords and shared secrets as plain strings.1
How encryption protects stored values
AES-GCM turns readable plain text into unreadable data called ciphertext. It is a proven method for encrypting a stored key.1
Encryption needs its own key to lock and unlock the data. Protecting that key is part of storing the API key safely.1
HKDF derives a key from a password and salt. It produces the number of bytes needed for the chosen key size.1
A 256-bit AES-GCM key needs 32 bytes. Those bytes can be made through key derivation rather than using the password directly.1
AES-GCM includes AEAD data to support checks on encrypted content. It stores ciphertext in a SealedBox.1
The function AES.GCM.seal() encrypts plain text into a sealed box. The function AES.GCM.open() opens that box to recover the plain text.1
Encrypted storage does not end the risk when an app sends its key over a network. Many services expect the key in readable form, where attacks that bypass TLS can expose it.1
Limit access and keep secrets out of code
Give each API key only the access it needs. Allow only chosen IP addresses where that fits the service.4
Key restrictions limit the ways a key can be used. They can reduce the harm if a key is exposed.3
Use short-lived secrets where possible. For most Google Cloud APIs, avoid authorisation keys in production and use short-lived service account credentials instead.4, 3
The Gemini API is an exception to that production guidance. Its service account must not have any IAM roles when using a bound authorisation key in production.3
Add sensitive files to .gitignore. Use automated secret scanning on repositories rather than relying on code reviews alone.4
Even strong secrets policies can miss newly created keys entering code. Scanning helps reveal secrets that have slipped back into a code base.4
Keep only the API keys you actively use. Delete keys you no longer need to reduce exposure to attacks.3
Keep API keys out of client code. The client can send requests to a server, which adds the key and calls the API.3
Managed secrets tools can store secrets with encryption and tight access controls. These tools take resources to set up and maintain. They are not a fit for every case.4
Storing sensitive notes in SimplyBoard
SimplyBoard encrypts entry content with AES-256-GCM before it leaves your device. Its design means SimplyBoard cannot read your notes.5, 6
New SimplyBoard vaults use an Argon2id-derived key to wrap the vault key. That key derivation happens in your browser.6
SimplyBoard uses your password, or a passphrase for Google sign-in, to derive an encryption key. Argon2id is memory-hard and resists GPU brute-force attacks.5
SimplyBoard servers store encrypted content and wrapped keys, not the plain text vault key. Your encryption secret or an optional recovery code can unlock the vault.5
An unlocked SimplyBoard session exposes readable content, which encryption does not protect. Keep your devices and saved recovery code secure.5, 6
SimplyBoard offers an optional recovery kit that can restore vault access. Set it up in Settings before you need it.5
An account password reset alone cannot decrypt your existing vault. Keep your encryption secret and recovery code somewhere safe.5
Sources
Frequently asked questions
- Is encoding an API key with Base64 or XOR enough to keep it safe?
- No. Base64, Base32 and simple XOR are not safe protection for API keys. Use proven encryption such as AES-GCM instead.
- Can team secrets management tools replace local notes for API keys?
- Managed secrets tools offer another way to store keys, with encryption and tight access controls. They take resources to set up and maintain, so they are not a fit for every case.
- Does client-side encryption protect notes when an app session is unlocked?
- No. An unlocked SimplyBoard session exposes readable content, which encryption does not protect. Keep your devices and saved recovery code secure.
Start writing with true privacy
Get Started Free


