Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk6 min

How to Secure API Keys and Other Secrets in Desktop Apps

Desktop apps are public clients: keep shared service secrets on a backend, use OAuth with PKCE for user sign-in, and store user tokens in OS credential storage.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not ship a confidential shared API key or OAuth client secret inside a desktop app. Treat a distributed desktop app as a public client: users can inspect its package and the machine running it. Use OAuth authorization code with PKCE for user sign-in, keep confidential service credentials on a backend, and store user-specific credentials in the operating system’s credential facility.

First decide what kind of secret you have

“API key” and “secret” can describe credentials with very different owners and trust boundaries. The right design depends on who the credential belongs to and where it must be used.

As an Amazon Associate I earn from qualifying purchases.

Credential or use Recommended direction Security boundary
A shared service credential needed by every installation Keep it on a backend that mediates the privileged API call; manage it through a secure vault workflow. Do not package a confidential shared key in the desktop client. The backend, not each installation, should be trusted with it.
A user’s access or refresh token Use a public-client OAuth flow with PKCE, then persist the user-specific credential in OS credential storage. Local storage can protect data at rest, but the running app may retrieve and use the credential.
A local Electron secret Use Electron safeStorage with provider-availability checks and platform-specific handling. Its documented protections differ across macOS, Windows, and Linux.
A macOS credential Use Keychain Services; review Apple’s current SecItem and data-protection-keychain guidance for the app’s use case. Keychain API choice and access behavior depend on the macOS implementation.
A Windows desktop credential Consider Credential Locker or another suitable Windows credential API. A compromise of an app running as the same user remains relevant.

Why a desktop package cannot keep a shared secret confidential

A desktop app runs on a device controlled by the person who installed it. A value included in source code, a compiled resource, a bundled environment file, or an obfuscated string can be extracted or observed. Obfuscation may make casual inspection less convenient, but it does not turn a distributed value into a confidential credential.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Microsoft’s guidance is explicit: “Desktop apps are public clients and must not embed client secrets.” It also says a native desktop app cannot protect a client secret from extraction. If a service requires a confidential client credential, move the exchange or privileged API call to a backend that can hold that credential. The desktop app can ask the backend to perform an authorized operation, while the backend applies its own authentication, authorization, and abuse controls. Microsoft: Implement OAuth 2.0 in Windows Apps

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

A credential that is intentionally public is a different case. If a provider offers a client identifier or limited public key for use in an app, treat it as an identifier rather than a secret: restrict its permissions and use server-side controls such as quotas or allowed-operation checks where available. Do not assume that renaming or encrypting a shared production key in the package makes it private.

Use OAuth with PKCE for user sign-in

When the app needs to act for an individual user, register it as a public OAuth client and use the authorization code flow with PKCE. PKCE helps protect the authorization-code exchange; it does not conceal a secret shipped in the package, and it does not make the app a confidential client. Do not add an embedded OAuth client secret to a native app as though it were required for this public-client pattern. Microsoft documents the public-client approach and PKCE for Windows apps. Microsoft OAuth guidance

Rank #2
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
  1. Start an authorization request for the user. Use the provider’s public-client configuration and PKCE rather than putting a client secret in the desktop package.
  2. Complete the authorization-code exchange using PKCE. The app proves possession of the verifier associated with the request; this protects the exchange, not other packaged values.
  3. Keep the resulting credential scoped to the user and the work the app needs to do. Request only the minimum permissions required for the feature.
  4. Persist user-specific tokens in OS credential storage. Retrieve them when needed and provide a sign-out or revocation path appropriate to the provider.

If an integration instead requires a confidential client credential, the exchange that uses it belongs on a backend. PKCE is not a substitute for that server-side boundary.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Store user credentials in the platform’s credential facility

macOS: Keychain Services

Apple describes Keychain Services as encrypted storage for small secrets, including credentials that an app saves after successful authentication and retrieves when reauthentication is needed. For macOS implementation choices, Apple recommends reviewing the SecItem API and the data protection keychain, while noting that macOS has more than one keychain API and implementation. Choose the API and access behavior for the app’s specific use case rather than treating “Keychain” as one universal configuration. Apple: Using the keychain to manage user secrets and Apple Technical Note TN3137: On Mac keychain APIs and implementations

Rank #3
Kensington Desktop & Peripherals Locking Kit 2.0, Black (K64424WW)
  • The strong lock head is designed for desktop PCs and other devices
  • 5mm Keying System featuring patented anti-pick Hidden Pin Technology
  • 2 adapters and cable trap secure peripheral accessories
  • Anchor plate allows devices without a Kensington Security Slot to be locked securely
  • 8-foot carbon steel cable is cut-resistant and anchors to desk, table or any fixed structure

Windows: Credential Locker

Microsoft documents Credential Locker for storing and retrieving credentials in Windows apps, including desktop applications such as WPF and WinForms. It is an option for persisting a user’s credentials, not a safe place to put a shared vendor key that every installation needs. Microsoft: Credential locker for Windows apps

Electron: safeStorage, with provider checks

Electron safeStorage uses operating-system cryptography to protect locally stored strings. Electron recommends its asynchronous encryptStringAsync and decryptStringAsync APIs over the synchronous API; the documentation describes the asynchronous API as non-blocking and supporting key rotation and temporary-unavailability handling. The protection depends on the platform and available provider, so check the selected backend and handle inadequate or unavailable storage deliberately. Electron: safeStorage API

Rank #4
Sale
Kensington Combination Cable T-Bar Standard Lock Slot for Laptops, Resettable 4 digit password with 6 Foot Cable, K64673AM
  • Computer lock for HP, Lenovo, Acer, Asus and other brands; not compatible with Dell or Alienware (see part # K68008WW)
  • Resettable 4-wheel Number code with 10, 000 possible combinations. Push-button design for one-handed engagement to easily attach lock
  • 6’ long carbon steel cable is cut-resistant and anchors to desks, tables, or any fixed structure
  • Attaches to laptops, desktops, TVs, monitors, hard drives, docking stations, projectors or any other device featuring a Kensington standard size security slot
  • Independently verified and tested for industry-leading standards in torque/pull, foreign implements, lock lifecycle, corrosion, key strength and other environmental condition
  • macOS: Electron’s documentation says encryption keys are stored in Keychain. It describes protection from other users and other apps in the same userspace, subject to user override and app-signing considerations.
  • Windows: DPAPI protects keys for the same user account, but Electron’s documentation says this does not protect against other apps running in the same userspace.
  • Linux: The provider varies by desktop environment. The asynchronous API can use the Secret portal or Secret Service, and an environment without a supported secret service may require a fallback. Electron warns that the synchronous API can use a hard-coded plaintext password when no supported secret store is available; basic_text identifies that condition.

These are the behaviors described in Electron’s safeStorage documentation at the time of review; framework behavior can change. In particular, do not silently treat a Linux fallback as equivalent to an operating-system secret store.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What local credential storage does—and does not—protect

OS-backed storage is useful for protecting persisted user credentials, especially against straightforward access to files on disk. It does not make a token inaccessible to an app that is authorized to retrieve it. If the app or the user’s session is compromised, a malicious process may be able to act through the running app or access credentials available to that user. Encryption at rest therefore reduces one exposure, but it does not replace careful permissions, a limited token scope, or a secure backend boundary.

Best Value
JAGTRADE Silver Metal Desktop Computer Lock with Key, Anti-Theft, Modern Style, Works with Most Desktops & Docking Stations
  • ★ Made of metal material, multi-layer plating color, do not fade, long-life
  • ★ Fine workmans ship make sure they are perfect to use.
  • ★ Protect your computer and its valuable data with this affordable computer lock.
  • ★ Works with most desktops, docking stations with built-in security locking slot hole.
  • ★ Works with most desktops, docking stations with built-in security locking slot hole.

This is why encrypting a shared service key before placing it in the app does not solve the distribution problem: the app must eventually recover or use the key, and every installation carries the same valuable credential. Keep that credential on a backend instead.

Handle credentials throughout their lifecycle

Storage is only one part of secret management. OWASP’s Developer Guide advises against hard-coding cryptographic keys, recommends secure vault storage, and describes lifecycle work spanning creation, storage, distribution, use, rotation, backup, recovery, revocation, suspension, and destruction. Apply equivalent discipline to API credentials. OWASP Developer Guide

  • Keep credentials out of source control, packaged defaults, crash reports, diagnostic logs, support bundles, and telemetry.
  • Use separate credentials for development and production, and grant each only the permissions it needs.
  • Plan how a credential can be rotated or revoked without requiring every user to reinstall the app.
  • Define recovery and backup procedures for credentials that must persist, and destroy credentials when they are no longer needed.
  • If a credential is exposed, revoke or rotate it and review logs and dependent systems for unauthorized use.
  • For shared or production service credentials, use a backend or a managed vault workflow rather than distributing the credential to clients.

Choose the architecture by asking where the credential must be used

If the value represents a user’s authority, use a public-client OAuth flow with PKCE and store the resulting user credential in platform credential storage. If the value grants the product shared service access, keep it on a backend or in a secure vault workflow and have the backend mediate use. If a local Electron secret must persist, use safeStorage with explicit provider checks and account for its documented platform limits. These choices protect different boundaries; no local encryption option can make a confidential shared secret safe once it is distributed to users.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.