Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make a system that needs to store some confident user information in a database. I intend on using OpenID for user authentication.

I would like encrypt the data in a way that it can only be decrypted when the user is logged in. What are the most common approaches to storing user's data securely in such a setup?

share|improve this question
Do you mean "securely" = "only the OpenID owner has any chance to decrypt it"? – Paŭlo Ebermann Oct 15 '11 at 1:49
That would be preferable. The system is to use that data infrequently only when the user is logged in and performs an explicit action. – ThePiachu Oct 15 '11 at 10:54
up vote 3 down vote accepted

Let's have a look on how OpenID works.

Alice wants to log into Bob's website using Charles as her identity provider. (So, you are Bob in this scenario.)

  1. Alice fills her OpenID into Bob's web form.
  2. Bob (or Bob's server, actually) transforms this into a canonical form, and fetches this resource to find out who is Alice's OpenID provider (
  3. Bob redirects Alice's browser to Charles' web site, Charles then somehow checks that it is really Alice who is currently logged in (maybe asking Alice for confirmation), and redirects Alice's browser again to Bob, sending also some information about Alice for Bob along the way.

The information which Bob gets is either signed using a MAC with some previously negotiated common secret (between Bob and Charles), or will be later checked by direct interaction between Bob and Charles.

There is nothing in here which can be used as a private/secret key for Alice's user data by Bob, so there is no way Bob can encrypt something in a way that can be only decrypted with Charles' help (i.e. Alice's OpenID).

(Also, as Alice can use OpenID delegation, Alice can change here OpenID provider without changing her OpenID, and you surely want to have her data being still decryptable.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.