I am creating a cross-platform application, in which I am encrypting all data using AES-GSM. So my problem is that I want to store private keys locally on the user's device (either Android, IOS, Web, etc.). But Since for login I have multiple options i.e either biometric(in case of offline), PIN, OTP, Email-Password, or Sign in with Google.

Since authentication is mainly using Firebase Authentication, and user can also open the app offline, after being logged in once before, using biometrics or PIN. How can I store the secret key? For PIN also, I am storing it using salted hash so I cannot encrypt key based on PIN, as users also have the option of logging in using Biometrics, which only returns true or false. Can anyone suggest me any solution?

  • @kelalaka That question asks the implementation of password-based encryption, to which answer is suggested to ask users if they want password-based encryption or not, but in my case, encryption and biometrics/social login both are required.
    – Vishnu
    Commented Oct 19, 2021 at 18:31
  • You say "private key" above, but that term is generally used for asymmetric a.k.a. public key cryptography; "secret key", "symmetric key", or even just "key" is what you want.
    – CBHacking
    Commented Oct 20, 2021 at 11:01
  • Secure way to hold private keys in the Android app
    – defalt
    Commented Oct 20, 2021 at 11:15

1 Answer 1


There is no way to store keys fully securely without requiring the user to input some form of credential (password, keyfile, etc.). Biometrics and similar can be used to authenticate the user, but not to decrypt secrets. However, if you're willing to trust that your attacker hasn't completely taken over the app (e.g. replaced the application binary, or gained the ability to run the app under a debugger, or gained root/admin privileges), then there are ways to securely (with those caveats) store secrets on most platforms.

Windows, MacOS, iOS, and Android all support encrypted key/credential storage suitable for secrets such as symmetric keys. Desktop Linux has no option that is reliably available, but does have some that can be checked for.

  • There is no app in Linux that uses TPM?
    – kelalaka
    Commented Oct 20, 2021 at 14:11
  • 1
    @kelalaka There might be such an app, but there's nothing I know of that is expected to be present in every desktop distro (the way e.g. GPG is, or the way Keychain is on Apple devices). Besides, TPM wouldn't necessarily fulfill the desired characteristics here; an attacker with sufficient access could still get the TPM to use the key for you, even if it wouldn't actually divulge it. For that matter, Windows and possibly some of the others offer that in software too; it's possible to get the key out anyhow but you need to compromise the whole OS, not just one app.
    – CBHacking
    Commented Oct 20, 2021 at 20:36
  • So, TPM is no way close to secure Enclave? an attacker with sufficient access could still get the TPM to use the key for you doesn't happen everywhere? Of cource, one may ask the passcode again and again...
    – kelalaka
    Commented Oct 20, 2021 at 20:37
  • TPMs are quite different from secure enclaves. A secure enclave can execute arbitrary code; a TPM only supports specific operations. TPMs are much easier to use (you can think of them as simply exposing an API that a program can use, like a library, whereas secure enclaves require writing your own program and loading it, plus working out a secure communication channel) and once a key is loaded even the OS can't get it out again, but the OS can watch the program use that key via the TPM, whereas the OS can't watch a secure enclave do anything (though it can see any data that comes out of it).
    – CBHacking
    Commented Oct 20, 2021 at 23:30
  • 1
    Right. Which is why I said the TPM doesn't actually protect you data (only your key) against an attacker with sufficient access.
    – CBHacking
    Commented Oct 21, 2021 at 0:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .