android.security.KeyChainException: java.lang.IllegalStateException: uid <> doesn't have permission to access the requested alias
Asked Answered
B

1

7

I'm getting this error when I try to fetch the previously chosen private key when I recreate the activity after rotating the screen.

I've seen this question here, which suggests that choosePrivateKeyAlias() needs to be called "at least once after the application is installed". In this case it has been called numerous times, including when the app is started up before the screen rotation happens - so why is it considered to be a new app? Is the uid changing somehow?

Here's the call:

PrivateKey privateKey = KeyChain.getPrivateKey(getBaseContext(), alias);

I've just noticed that the other question was using getCertificateChain rather than getPrivateKey - is that the difference?

Bollen answered 22/9, 2017 at 11:6 Comment(2)
Are you sure that the alias you are using is actually the string returned by the alias callback? Could you post more of your code around that call?Estes
You were right, I'd not actually stored it properly and so was looking for the wrong alias. If you put this suggestion as an answer I will mark it as correct.Bollen
E
8

For posterity's sake, and to repeat my comment, the issue was that the alias was not being properly stored, and so this call attempted to access an entirely unrelated, or nonexistent, private key.

Estes answered 26/9, 2017 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.