Quick scan which data (hmac/fernet) can be decrypted with a key? I am designing a secure vault, which stores tens of thousands of encrypted messages and authenticated with Fernet/HMAC, A user query the vault with a key, could I use some kind of index to tell if the key can be used to decrypt any of the stored messages?

Or do I have to try decrypt them one by one?
Found a stupidly simple solution: Create an index of md5(key).

Alternatively, replace md5 with hash method of your choice.