I have a scenario where semi-sensitive [1] data for a corporate web application is to be stored in the browser's localized storage (Indexed DB to be specific, via JavaScript).

The intention is to encrypt the data (AES 256) at the server level with a "master" key/passphrase, but then send a 'time-bombed' generated key that would enable decrypting the data... but only for a certain amount of time - e.g. 2-4 hours.

I've been led to believe that this is possible - however I haven't found any documentation indicating how to generate temporary keys.

If this concept is possible a link to, or indication of what the API/method call would be named would be helpful. If this is possible, but only in other encryption schemes (e.g. SHA-512?) I'd be grateful for a nudge in the right direction.

[1] - No credit cards, financial or other scary stuff. Just things that the user might not want a casual person walking by to be able to read. Yes I'm fully aware that "security" and "JavaScript" should likely not be uttered in the same sentence but this is all HTML5 offers.

  • 3
    AES-256 is a mathematical algorithm; it doesn't have any notion of "hours" or of "time-bombed keys" (calling it now with key k and ciphertext c gives the same result as calling it in six weeks with key k and ciphertext c). AES is also symmetric; you can only decrypt with the key it was encrypted with. You're looking for a higher-level system than AES.
    – cpast
    May 11, 2015 at 21:17
  • 2
    As a side note, no decryption algorithm can support expiring keys unless it interacts with a server. If I can run D(k,c) now, I can run it whenever, assuming I have k and c. The only way to have a key expire is to force someone to forget the key, forget the ciphertext, or make decryption impossible without talking to a server under your control (but once they decrypt it once, they can keep that data and decrypt it again later).
    – cpast
    May 11, 2015 at 21:20
  • @cpast, you could post that as an answer.
    – Celada
    May 11, 2015 at 21:29

1 Answer 1


First, about AES-256 in particular: AES-256 is a symmetric cryptosystem. Decryption and encryption use the same key; if you encrypt stuff with a master key, you have to give that master key to whatever's decrypting stuff or else it can't decrypt stuff. You may have read about master and session keys, but that is about stuff happening before AES encryption -- to decrypt the output of AES-Encrypt(k,m), the client must know k.

Second, for time-based decryption: Encryption and decryption algorithms are mathematical functions. They have no notion of an hour; they cannot be made to work one way today and a different way in six weeks. A function takes an input and gives an output; it always gives the same output if given the same input, no matter where or when it's being run. Since neither key nor ciphertext degrades over time unless you actively destroy it, there is no way to have "time-bombed" decryption that happens entirely on the client side. This is not AES-specific; in every encryption system, if you have the information needed to decrypt the data now, you can use that information any time you want.

The only way to get some sort of time-bomb encryption is to make it so that the client simply does not have all the information it needs to decrypt. You need a system where it can't decrypt without contacting a server you control and getting some information that couldn't otherwise be figured out. Even then, if that information is stored locally, an attacker doesn't need to contact you to use it a second time unless you re-encrypted the data.

You must log in to answer this question.

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